Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


It's not recommended anymore. Optional types should be explicit. https://peps.python.org/pep-0484/#union-types


Each 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"




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: