__getnewargs__ for a subclass incompatible with return type of supertype
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Here is an example commit with the issue: https://github.com/eli-schwartz/meson/commit/4d204bb81869422a102264611d9aea314a1ac2ca
mypy.ini: https://github.com/mesonbuild/meson/blob/27626124d0bdd89f5f276f70a73b4713aa3aac3d/.mypy.ini
$ mypy --version
mypy 0.961 (compiled: yes)
$ mypy mesonbuild/interpreter/primitives/string.py
mesonbuild/interpreter/primitives/string.py:211:5: error: Return type "Tuple[str, str]" of "__getnewargs__" incompatible with return type "Tuple[str]" in supertype "str"
I subclassed str and treat it specially with its own incompatible __new__() to enforce a specific creation pattern. After discovering I need to pickle it as well, I added a __getnewargs__() which is also incompatible. mypy is happy with my incompatible new, but not with the getnewargs that needs to match the argument contract of new.
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
Reproduce the report with mypy 0.961 using mesonbuild/interpreter/primitives/string.py and the linked .mypy.ini configuration. Inspect how the subclass’s new and getnewargs signatures are checked against str, then verify the intended pickle case is handled without the reported incompatible-return diagnostic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100