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
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.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...