Consistently mark types with `| MaybeNone` whenever it is applicable
I noticed that there's a special type alias MaybeNone that represents this specific intent:
We didn't dare to change the type to
X | Noneso instead we changed it toAny
You can find an example in a relatively recent addition of this.
And while this approach makes me very sad, it is good that such cases are marked with MaybeNone, for the purpose of looking at them specially. Maybe some type checker will arise that will have specific handling for it and do something smarter instead.
With that in mind, it would be good to ensure that all such cases are consistently marked.
I noticed at least one case that is not marked like this. It has | Any directly written instead of | MaybeNone. This is in re.match.group*:
https://github.com/python/typeshed/blob/6feca188689e14cdacd8dbf8bc9cf0635993027a/stdlib/re.pyi#L93-L117
Feel free to submit a PR!
And if you're motivated to get this to a better state, consider writing a PEP for something like python/typing#1096.
Or python/typing#566, which would replace this with AnyOf[X, None] and could also be controlled with strictness flags.
Sure, if AnyOf is ever approved, then in this repository one could find all occurrences of MaybeNone and replace them.
But that's what I want to track in this issue - that all the occurrences are readily marked for this. So that then it's more straightforward to apply any such ideas.
But not sure whether I'll actually send PRs for this
@JelleZijlstra Looks like this issue can be closed since the PR: https://github.com/python/typeshed/pull/12855 was merged.
That PR is only for stdlib, I haven't looked at stubs of third party libraries