Consistently mark types with `| MaybeNone` whenever it is applicable
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.1k
- Forks
- 2.1k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 82
Description
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*:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with stdlib/re.pyi, especially the re.match.group* definitions around lines 93–117, and compare them with the MaybeNone alias in stdlib/_typeshed/init.pyi. Review similar cases across the stubs where this intent is represented with Any; done means applicable cases consistently use MaybeNone instead, with no unmarked exceptions found.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100