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

attrs.evolve: support generics and unions #15050

Merged
merged 4 commits into from
Apr 21, 2023

Conversation

ikonst
Copy link
Contributor

@ikonst ikonst commented Apr 13, 2023

Fixes attrs.evolve signature generation to support the inst parameter being

  • a generic attrs class
  • a union of attrs classes
  • a mix of the two

In the case of unions, we "meet" the fields of the potential attrs classes, so that the resulting signature is the lower bound.

Fixes #15088.

@ikonst ikonst force-pushed the 2023-04-13-attrs-evolve-union branch from be7ae9b to aed08ca Compare April 13, 2023 18:26
@ikonst ikonst changed the title 2023 04 13 attrs evolve union attrs.evolve: support generics and unions Apr 13, 2023
@ikonst ikonst marked this pull request as draft April 13, 2023 18:33
@ikonst ikonst force-pushed the 2023-04-13-attrs-evolve-union branch 2 times, most recently from 8c976f8 to b32252f Compare April 13, 2023 18:49
@ikonst ikonst marked this pull request as ready for review April 13, 2023 18:49
@github-actions

This comment has been minimized.

mypy/plugins/attrs.py Outdated Show resolved Hide resolved
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@ikonst ikonst force-pushed the 2023-04-13-attrs-evolve-union branch from 6721b51 to 8c90ab3 Compare April 14, 2023 02:22
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@ikonst
Copy link
Contributor Author

ikonst commented Apr 14, 2023

@hauntsaninja since you also reviewed #15022

I looked into existing code (checkmember, meet) but didn't find anything that did quite that, but meet_types is obviously useful.

@ikonst
Copy link
Contributor Author

ikonst commented Apr 18, 2023

👋 @hauntsaninja (trying to make it more readable, but it's really not too scary)

@github-actions

This comment has been minimized.

@ikonst ikonst force-pushed the 2023-04-13-attrs-evolve-union branch from 857c624 to 10d9e91 Compare April 20, 2023 12:37
@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked 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.

Overall seems reasonable, could you also add a test case for constrained type variables?

mypy/plugins/attrs.py Show resolved Hide resolved
@ikonst
Copy link
Contributor Author

ikonst commented Apr 20, 2023

could you also add a test case for constrained type variables?

I believe there's alreadytestEvolveTypeVarConstrained

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.

Thank you!

@hauntsaninja hauntsaninja merged commit 2a4c473 into python:master Apr 21, 2023
@ikonst ikonst deleted the 2023-04-13-attrs-evolve-union branch April 21, 2023 10:05
ikonst added a commit to ikonst/mypy that referenced this pull request Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generic type parameters to Argument 1 of attrs.evolve only unify under very specific circumstances (mypy 1.2)
3 participants