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

Fix inheriting from generic @frozen attrs class #15700

Merged
merged 3 commits into from
Aug 12, 2023

Conversation

ikonst
Copy link
Contributor

@ikonst ikonst commented Jul 18, 2023

Fixes #15658.

@github-actions

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)
Copy link
Contributor Author

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 :(

Copy link
Contributor Author

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).

@ikonst
Copy link
Contributor Author

ikonst commented Jul 31, 2023

@hauntsaninja can take a look?

@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Collaborator

@hauntsaninja hauntsaninja left a 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

@hauntsaninja hauntsaninja merged commit 0e4521a into python:master Aug 12, 2023
17 checks passed
@ikonst ikonst deleted the issue-15658 branch August 12, 2023 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mypy errors out with attrs, generics and inheritance
2 participants