Skip to content

Conversation

@ikonst
Copy link
Contributor

@ikonst ikonst commented Jul 18, 2023

Fixes #15658.

@github-actions

This comment has been minimized.

# 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
@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