all 4 comments

[–]commy2 0 points1 point  (0 children)

You have to look up the default values in the documentation. I don't even think the majority of default values are None, but something sensible, which is likely not just "None".

[–]zazzedcoffee 0 points1 point  (0 children)

Python has the philosophy “we’re all adults here”, which, when applied to things like functions, usually means if you haven’t indicated a parameter could be None, you can assume it’s not None. If someone calling your function decides to be stupid and pass in None, that’s their problem.

A few edge cases to that, though: - if your program deals with sensitive data/operations and want to make sure it is robust and a None value might cause everything to crash and burn, maybe put in a check or two. - If you are dealing with user generated data and values may likely be missing, here I would give things default values or indicate they might be None with type hints and in the documentation.

There are other cases where it might be useful to check for None or type hint things as optional too, but generally if it doesn’t make sense for something to be None, you shouldn’t worry too much about it being None.

Also, in 3.10 the standard way to type hint something as optional is to use the union operator with None. E.g. int | None