Skip to content

Fix inheriting from generic @frozen attrs class - #15700

Merged
hauntsaninja merged 3 commits into
python:masterfrom
ikonst:issue-15658
Aug 12, 2023
Merged

Fix inheriting from generic @frozen attrs class#15700
hauntsaninja merged 3 commits into
python:masterfrom
ikonst:issue-15658

Conversation

@ikonst

Copy link
Copy Markdown
Contributor

Fixes#15658.

@github-actions

This comment has been minimized.

Comment threadmypy/plugins/attrs.py
# 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
Copy Markdown
ContributorAuthor

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.

defconverter(s: str) ->int:
returnint(s)
@attrs.defineclassC:
x: int=attrs.field(converter=converter)

The attribute.init_type will be str here :(

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

@hauntsaninja can take a look?

@github-actions

Copy link
Copy Markdown
Contributor

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

@hauntsaninjahauntsaninja left a comment

Copy link
Copy Markdown
Collaborator

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:masterAug 12, 2023
@ikonst
ikonst deleted the issue-15658 branch August 12, 2023 12:06
Sign up for freeto 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

@ikonst@hauntsaninja