-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
type[] inside a class with an attribute named type gives an error #14245
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
Comments
This is correct behaviour from mypy (duplicate of #14205). Possible workarounds are:
|
Thanks @AlexWaygood! Perhaps we should add this exact example of workarounds in the docs? Do you think it would make sense to open a PR for this as I guess I am not the only person hitting this. |
Yeah, I wondered about that. It seems like it'll crop up more and more as more people switch to PEP 585 syntax in their projects. It might make a good addition to this page: https://mypy.readthedocs.io/en/stable/common_issues.html |
As discussed with @AlexWaygood in python#14245 (comment) adding a common issue entry for the problem of hitting overshadowing a built-in keyword when upgrading to PEP584 syntax
As discussed with @AlexWaygood in python#14245 (comment) adding a common issue entry for the problem of hitting overshadowing a built-in keyword when upgrading to PEP584 syntax
As discussed with @AlexWaygood in python#14245 (comment) adding a common issue entry for the problem of hitting overshadowing a built-in keyword when upgrading to PEP585 syntax
As discussed with @AlexWaygood in python#14245 (comment) adding a common issue entry for the problem of hitting overshadowing a built-in keyword when upgrading to PEP585 syntax
As discussed with @AlexWaygood in python#14245 (comment) adding a common issue entry for the problem of hitting overshadowing a built-in keyword when upgrading to PEP585 syntax
Bug Report
Using
type[]
instead ofType[]
in a class with an attribute namedtype
gives an error.To Reproduce
Consider the following:
https://gist.github.com/mypy-play/da5ef553b28dee4ff64e6bac829ab260
https://mypy-play.net/?mypy=0.991&python=3.9&gist=da5ef553b28dee4ff64e6bac829ab260
Expected Behavior
I would expect to not see any error. Same as I do when I import
Type
fromtyping
and use that instead. Then there is no error.Actual Behavior
I am sure it's something to do with the class using a reserved keyword for its attribute and that somehow clashing with the
type
keyword of typing.As I said above if you replace
type
withtyping.Type
it all works fine.Your Environment
--install-types --non-interactive
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: