-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
get_attribute_hook does not trigger for class attributes, get_base_class_hook cannot resolve class attr types #9645
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
Labels
bug
mypy got something wrong
Comments
FuegoFro
added a commit
to FuegoFro/mypy
that referenced
this issue
Jan 5, 2021
This adds a hook to modify attributes on *classes* (as opposed to the existing attribute hook, which is for attributes on *instances*). This also adds a test to demonstrate the new behavior. The modifications and added tests were modeled off of python@3acbf3f. This is intended to solve python#9645
FuegoFro
added a commit
to FuegoFro/mypy
that referenced
this issue
Mar 9, 2021
This adds a hook to modify attributes on *classes* (as opposed to the existing attribute hook, which is for attributes on *instances*). This also adds a test to demonstrate the new behavior. The modifications and added tests were modeled off of python@3acbf3f. This is intended to solve python#9645
FuegoFro
added a commit
to FuegoFro/mypy
that referenced
this issue
Apr 5, 2021
This adds a hook to modify attributes on *classes* (as opposed to the existing attribute hook, which is for attributes on *instances*). This also adds a test to demonstrate the new behavior. The modifications and added tests were modeled off of python@3acbf3f. This is intended to solve python#9645
FuegoFro
added a commit
to FuegoFro/mypy
that referenced
this issue
May 19, 2021
This adds a hook to modify attributes on *classes* (as opposed to the existing attribute hook, which is for attributes on *instances*). This also adds a test to demonstrate the new behavior. The modifications and added tests were modeled off of python@3acbf3f. This is intended to solve python#9645
denbeigh2000
pushed a commit
to denbeigh2000/mypy
that referenced
this issue
Jul 28, 2021
This adds a hook to modify attributes on *classes* (as opposed to the existing attribute hook, which is for attributes on *instances*). This also adds a test to demonstrate the new behavior. The modifications and added tests were modeled off of python@3acbf3f. This is intended to solve python#9645
denbeigh2000
pushed a commit
to denbeigh2000/mypy
that referenced
this issue
Jul 29, 2021
This adds a hook to modify attributes on *classes* (as opposed to the existing attribute hook, which is for attributes on *instances*). This also adds a test to demonstrate the new behavior. The modifications and added tests were modeled off of python@3acbf3f. This is intended to solve python#9645
denbeigh2000
pushed a commit
to denbeigh2000/mypy
that referenced
this issue
Jul 29, 2021
This adds a hook to modify attributes on *classes* (as opposed to the existing attribute hook, which is for attributes on *instances*). This also adds a test to demonstrate the new behavior. The modifications and added tests were modeled off of python@3acbf3f. This is intended to solve python#9645
FuegoFro
added a commit
to FuegoFro/mypy
that referenced
this issue
Aug 4, 2021
This adds a hook to modify attributes on *classes* (as opposed to the existing attribute hook, which is for attributes on *instances*). This also adds a test to demonstrate the new behavior. The modifications and added tests were modeled off of python@3acbf3f. This is intended to solve python#9645
denbeigh2000
pushed a commit
to denbeigh2000/mypy
that referenced
this issue
Aug 11, 2021
This adds a hook to modify attributes on *classes* (as opposed to the existing attribute hook, which is for attributes on *instances*). This also adds a test to demonstrate the new behavior. The modifications and added tests were modeled off of python@3acbf3f. This is intended to solve python#9645
ddfisher
pushed a commit
to discord/mypy
that referenced
this issue
Nov 19, 2021
This adds a hook to modify attributes on *classes* (as opposed to the existing attribute hook, which is for attributes on *instances*). This also adds a test to demonstrate the new behavior. The modifications and added tests were modeled off of python@3acbf3f. This is intended to solve python#9645
hauntsaninja
pushed a commit
that referenced
this issue
May 7, 2022
This adds a get_class_attribute_hook to plugins to modify attributes on classes (as opposed to the existing get_attribute_hook, which is for attributes on instances). Fixes #9645
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug Report
I wasn't sure how to best phrase title and/or description for this, so edits/suggestions/renames are welcomed.
The
get_attribute_hook
plugin hook is not triggered for attributes/variables on classes. It seems to only trigger for attributes/variables on instances. Additionally, I seem to be unable to resolve types of class variables in the hook return byget_base_class_hook
.To Reproduce
Given the source file
and the plugin
Expected Behavior
I would expect that an
ATTRIBUTE HOOK FOR
line would be printed for theConcrete.foo
andConcrete.bar
accesses. Alternatively, I'd expect to be able to eventually get a non-None
type for thefoo
attribute in the base class hook.Actual Behavior
The
ATTRIBUTE HOOK FOR
is never printed for theConcrete.*
accesses and we never get a non-None
type forfoo
(we reach the final iteration).If there's a way to accomplish the
Would like this to show up as type
comments with the existing plugin hook behaviors, that also works for me! Note, I've seen other plugins use theget_function_hook
to modify the return type and therefore the type of the class var, but I didn't see a way to know that the result of the function would be stored in a class var, since I wouldn't want every builder method to be automatically converted.Your Environment
mypy 0.800+dev.f220ce50725ed7f117832b9f03aed4d1a9508e00
--show-traceback --warn-unused-configs --config-file <file>
mypy.ini
(and other config files):3.7.6
The text was updated successfully, but these errors were encountered: