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

[red-knot] Support implicit class attributes (only defined in a @classmethod) #15965

Open
Tracked by #14164
sharkdp opened this issue Feb 5, 2025 · 0 comments
Open
Tracked by #14164
Labels
red-knot Multi-file analysis & type inference

Comments

@sharkdp
Copy link
Contributor

sharkdp commented Feb 5, 2025

Similar to how we support implicit instance attributes, we should also support implicitly defined class attributes. More concretely, we want the TODO comment here to be resolved, i.e. there should be no unresolved-attribute diagnostic:

class C:
@classmethod
def class_method(cls):
cls.pure_class_variable = "value set in class method"
# for a more realistic example, let's actually call the method
C.class_method()
# TODO: We currently plan to support this and show no error here.
# mypy shows an error here, pyright does not.
# error: [unresolved-attribute]
reveal_type(C.pure_class_variable) # revealed: Unknown

The implementation for this can probably re-use most of the machinery introduced in this PR. In particular, the Type::implicit_instance_attribute method.

@sharkdp sharkdp changed the title Support implicit class attributes (only defined in a @classmethod) [red-knot] Support implicit class attributes (only defined in a @classmethod) Feb 5, 2025
@sharkdp sharkdp added red-knot Multi-file analysis & type inference help wanted Contributions especially welcome and removed help wanted Contributions especially welcome labels Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

No branches or pull requests

1 participant