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] Diagnostic for conflicting declared attribute types #15964

Open
Tracked by #14164
sharkdp opened this issue Feb 5, 2025 · 0 comments
Open
Tracked by #14164

[red-knot] Diagnostic for conflicting declared attribute types #15964

sharkdp opened this issue Feb 5, 2025 · 0 comments
Labels
help wanted Contributions especially welcome red-knot Multi-file analysis & type inference

Comments

@sharkdp
Copy link
Contributor

sharkdp commented Feb 5, 2025

We should emit a diagnostic when we see conflicting declared types of attributes, either between the declaration in the class body and declarations in a method, or between annotated assignments in different methods. We have existing tests for this scenario (see TODO comments):

class C:
z: int
def __init__(self) -> None:
self.x = get_int()
self.y: int = 1
def other_method(self):
self.x = get_str()
# TODO: this redeclaration should be an error
self.y: str = "a"
# TODO: this redeclaration should be an error
self.z: str = "a"

part of: #14164

@sharkdp sharkdp added the red-knot Multi-file analysis & type inference label Feb 5, 2025
@sharkdp sharkdp changed the title Emit a diagnostic when we see conflicting declared types between class body and __init__ (see TODO in own_instance_member) [red-knot] Diagnostic for conflicting declared attribute types Feb 5, 2025
@sharkdp sharkdp added the help wanted Contributions especially welcome label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Contributions especially welcome red-knot Multi-file analysis & type inference
Projects
None yet
Development

No branches or pull requests

1 participant