-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Fix inheriting from generic @frozen attrs class #15700
Conversation
This comment has been minimized.
This comment has been minimized.
@@ -803,7 +803,7 @@ def _make_frozen(ctx: mypy.plugin.ClassDefContext, attributes: list[Attribute]) | |||
else: | |||
# This variable belongs to a super class so create new Var so we | |||
# can modify it. | |||
var = Var(attribute.name, ctx.cls.info[attribute.name].type) | |||
var = Var(attribute.name, attribute.init_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this is problematic with converters, e.g.
def converter(s: str) -> int:
return int(s)
@attrs.define
class C:
x: int = attrs.field(converter=converter)
The attribute.init_type
will be str
here :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, nm, by the time it's deserialized, it's int
again (there's also converter_init_type).
@hauntsaninja can take a look? |
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the most familiar with attrs plugin, but this seems reasonable
Fixes #15658.