After seeing the (awesome) new Annotated
type annotation in python 3.9 (varaidic type constraints!), I rushed to upgrade so I could check them out.
(https://docs.python.org/3/library/typing.html?highlight=valuerange)
But when I tried using ValueRange[min,max]
or MaxLen[n]
- I couldn't seem to find them anywhere..
PyCharm didn't offer me any help, and they don't seem to be in the typing
module where I might expect them.
The docs feature them but googling I can't find any reference online as to how to actually import them.
Are they not in the language yet? or just in some new module I'm not aware of?
As others have said, these classes are just an example of what can be annotated. Annotation just grabs a certain variable and adds some "hints" to them via the class you created (MaxLen, ValueRange, etc).
You can then obtain which "hints" are related to every parameter using get_type_hints
, and crawl one per one the parameters with its hits and do the checks you want (not the idea Annotation was intended, though I also found it interesting). You have a full example in this other post.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With