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

AttributeError for mixin classes. #1996

Closed
ghost opened this issue Aug 8, 2016 · 1 comment
Closed

AttributeError for mixin classes. #1996

ghost opened this issue Aug 8, 2016 · 1 comment

Comments

@ghost
Copy link

ghost commented Aug 8, 2016

Suppose I have a mixin class "FooMixin" for a class "Bar" and inside the mixin are used base attributes / methods from the "Bar" class.

Mypy returns AttributeError:

mixins/file.py:line_number: error: "FooMixin" has no attribute "blabla"

I would except from mypy to browse a project directory to find a class, where is the "FooMixin" inherited and check, if the attributes and methods are defined here. If not, print the error above.

@ddfisher
Copy link
Collaborator

ddfisher commented Aug 8, 2016

That's a reasonable expectation, but it's not how mypy works at the moment. Mypy doesn't check all the places a mixin is used. Instead, it requires classes to be valid by themselves. Our recommended approach to mixins is to define an ABC that declares the API they can use, and to have both the mixin and classes that use the mixin inherit from the ABC.

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

1 participant