Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Yeah, it doesnt really matter if you call
rich.inspect(ui)
orrich.inspect(UserInfo)
- output should be +/- the same.You can try to run this example with
mypy
or other type python type "validators/checkers". They will tell you that you always should typehint all possible values, likestr
orNone
.This typehint doesn't really do anything, they are just HINTS. Like TypeVars, TypeAliases, etc.
Cool conversation,. tbh, thank you
Thank you for your feedback! I may be over looking what you're trying to explain. On line
533
of your example,str = None
is applied to_field_no_pipe
in thehelp
doctstring when you use therich.inspect(, help=True)
method on theui
object, no?So, are you referring to the print out on line
535
of your example:'_field_no_pipe', <class 'str'>
? This is where you feel it should displaystr | None
instead, so future developers will know this field type can beNone
as well, correct? However, this is the objtype
and not thehelp
doctstring of the obj, correct? Again, thank you for feedback!In doc's example they are using pipes for fields too. When no
= field()
applied to self.variables in@dataclass
- dataclasses appy it automatically. I've wrote this little experiment to test typehinting:As you can see - typehint for
_field_no_pipe: str = None
was not applied forhelp
docstring and future developers will not know that fieldsjob
andhobbies
can beNone
(and they can be!), so| None
is required.P.S. I don't really agree with statement
Init-only can have no "| None" in typehints
, because it can cause some trouble with later computation. And because of that C# and Kotlin have quistion marks, that indicating that some var can be null (someVar?.name
). You should always apply all posible types that variable can be. In this case - job and hobbies can be optional fields for user.Thanks for the feedback. According to the Python docs, it uses this
| None = None
typehint only forInit-only
variables. Please let me know your feedback if you agree or disagree ~ thanks!I have this too
typehint should also contain
| None
, even whenfield(defalut=None)
is appliedCan someone explain pls whatwill happen is this scenario:
User
haverank -7
,task
haverank 4
diff_progress = current_progress + 10 * (user_rank - task_rank)^2
- because task_rank > user_rankdiff_progress = 0 + 10 * (-7-4)^2 = 10 * 121 = 1210
So, user rank changes from
-7
to-6
anddiff_progress
becomes1110
(-100 for rank up)But what will happen with
diff_progress
after this? I should recalculate it on each step of ranking up? Task description is very unclear...