Skip to content

__getnewargs__ for a subclass incompatible with return type of supertype #13309

Open
@eli-schwartz

Description

@eli-schwartz

Here is an example commit with the issue: eli-schwartz/meson@4d204bb

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongfalse-positivemypy gave an error on correct codetopic-inheritanceInheritance and incompatible overrides

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions