Skip to content

Mypy does not detect overriding __new__ with a different number of arguments #5402

Description

@RadixSeven

On the code below, mypy 0.620 (executed as mypy foo.py) under python 3.6.3 says:

foo.py:17: error: Too few arguments for "FR"

despite the fact that the code is fine. I expect no warnings.

from typing import Type, NamedTuple


_FR = NamedTuple('_FR', [
    ('forward', str),
    ('reverse', str)
])


class FR(_FR):
    def __new__(cls: Type['FR'], fw: str) -> 'FR':
        # The ignore on the next line works around a bug
        # reported as fixed https://github.com/python/typeshed/issues/2091
        #
        # NOTE: it is still not fixed with 
        # mypy-0.630+dev.b2d61741623f2a0573f2b1bdb8391ceed862cf69
        return super().__new__(cls, fw, fw[::-1])  # type: ignore


print(FR('stuff'))

I also tried executing with latest from git (mypy-0.630+dev.b2d61741623f2a0573f2b1bdb8391ceed862cf69) and the error persists.

Activity

  1. JelleZijlstra commented on Jul 29, 2018

    @JelleZijlstra
    Member

    This is #2852 and #1279.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions