mypy
mypy copied to clipboard
__getnewargs__ for a subclass incompatible with return type of supertype
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.