Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
RadixSeven opened this issue Jul 29, 2018 · 1 comment

Comments

@RadixSeven
Copy link

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.

@JelleZijlstra
Copy link
Member

This is #2852 and #1279.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants