Skip to content

Confusing note if Mypy cannot find __init__ of a class #4132

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

Closed
Zac-HD opened this issue Oct 19, 2017 · 5 comments
Closed

Confusing note if Mypy cannot find __init__ of a class #4132

Zac-HD opened this issue Oct 19, 2017 · 5 comments
Labels

Comments

@Zac-HD
Copy link
Contributor

Zac-HD commented Oct 19, 2017

This is another entry in the genre of confusing interactions between Mypy and attrs, extracted from #2088 by request of @gvanrossum. Let's start with an example:

import attr
@attr.s()
class A:
    arg = attr.ib()
A(arg=1)
$ python -m mypy --ignore-missing-imports a.py
a.py:5: error: Unexpected keyword argument "arg" for "A"
Lib/mypy/typeshed/stdlib/3/builtins.pyi:39: note: "A" defined here

Mypy can't find A.__init__, so it points to the stub for object.__init__... but misreports it as the definition of A.

@elazarg
Copy link
Contributor

elazarg commented Oct 19, 2017

This has nothing to do with attrs, since mypy knows nothing about it. Minimal repro:

class A: pass
A(a=1)

@Zac-HD
Copy link
Contributor Author

Zac-HD commented Oct 27, 2017

This has nothing to do with attrs, since mypy knows nothing about it. Minimal repro: <...>

Well, mypy gives an unhelpful message for both examples - the difference is that my example works at runtime, while yours raises TypeError: object() takes no parameters

@elazarg
Copy link
Contributor

elazarg commented Oct 27, 2017

And this difference amounts to "mypy knows nothing about attrs" which is a feature request and not this bug. Supporting attrs will not resolve this bug, while handling my example will.
(I admit I am not sure what are we discussing here).

@gvanrossum
Copy link
Member

gvanrossum commented Oct 27, 2017 via email

@Zac-HD Zac-HD closed this as completed Jun 21, 2018
@Zac-HD
Copy link
Contributor Author

Zac-HD commented Jun 21, 2018

The error message for this case has been improved; as of mypy 0.610 it is

a.py:5: error: Unexpected keyword argument "arg" for "A"

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

4 participants