4 ms·
That’s not a type error in python. All types in puthon (afaik) accept ‘None’ as a value. For example, try: a : int = None It will succeed. This is done (
by seanhunter 3y ago
That’s not a type error in python. All types in puthon (afaik) accept ‘None’ as a value.
For example, try:
a : int = None
It will succeed. This is done (I think) so you can tell whether optional arguments are defined, declare variables before use (eg if you have a conditional with two branches both setting a different value for a variable sibce python blocks aren’t expressions) and that kind of thing.
- veber-alex 3y agoEach type checker can implement however strict rules it wants. And pyright gives the correct answer here: Expression of type "None" cannot be assigned to declared type "int" Type "None" cannot be assigned to type "int"
- SushiHippie 3y agoIt's not recommended anymore. Optional types should be explicit. https://peps.python.org/pep-0484/#union-types https://peps.python.org/pep-0484/#union-types