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

false negative with underscore on parameter name #9447

Open
KotlinIsland opened this issue Sep 16, 2020 · 2 comments
Open

false negative with underscore on parameter name #9447

KotlinIsland opened this issue Sep 16, 2020 · 2 comments
Labels

Comments

@KotlinIsland
Copy link
Contributor

The following code reports no errors with mypy but will fail at runtime:

class Base:
    def a(self, a: int) -> None: ...

class Derived(Base):
    def a(self, _a: int) -> None:  ...

def foo(b: Base) -> None:
    b.a(a=1)

foo(Derived())
@KotlinIsland KotlinIsland added the bug mypy got something wrong label Sep 16, 2020
@KotlinIsland
Copy link
Contributor Author

Same thing with double underscore on parameter name

@gvanrossum
Copy link
Member

This is a tough one. The problem is that this kind of error is pretty common in class hierarchies, and if we were to report Derived.a as an error because the parameter names don't match, I'm sure we'd get quite a few complaints. So I'm not sure what to do except propose that maybe this ought to be yet another strictness flag (but we already have too many of those).

PS. There's nothing special about underscores here -- mypy just doesn't care about the argument names. For inheritance it just checks whether the type of Base.a reduced to what can be expressed using Callable is a supertype of the type of Derived.a when reduced to a Callable.

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

No branches or pull requests

2 participants