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

Additional validation for TypeVar defaults (PEP 696) #15442

Merged
merged 2 commits into from
Jun 15, 2023

Conversation

cdce8p
Copy link
Collaborator

@cdce8p cdce8p commented Jun 15, 2023

Check that default type is a subtype of bound or one of the constraint types.

Add default to nodes __match_args__. Missed that initially.

Ref: #14851

@github-actions
Copy link
Contributor

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

@A5rocks
Copy link
Contributor

A5rocks commented Jun 15, 2023

Add default to nodes __match_args__. Missed that initially.

I've been wondering: why don't we use dataclasses? I probably missed something.

@AlexWaygood
Copy link
Member

AlexWaygood commented Jun 15, 2023

Add default to nodes __match_args__. Missed that initially.

I've been wondering: why don't we use dataclasses? I probably missed something.

Until recently it wasn't an option, because we supported Python 3.6, and dataclasses were introduced in Python 3.7. Slotted classes are also more performant, though, and you can't do slotted classes with dataclasses on <3.10. (Performance matters quite a lot for mypy!)

@JelleZijlstra
Copy link
Member

Slotted classes are also more performant, though, and you can't do slotted classes with dataclasses on <3.10. (Performance matters quite a lot for mypy!)

You can, you just have to write out the __slots__ manually.

@JelleZijlstra JelleZijlstra merged commit 66b96ed into python:master Jun 15, 2023
@AlexWaygood
Copy link
Member

Slotted classes are also more performant, though, and you can't do slotted classes with dataclasses on <3.10. (Performance matters quite a lot for mypy!)

You can, you just have to write out the __slots__ manually.

Good point, I forgot about that.

@cdce8p cdce8p deleted the TypeVar-04-additional-validation branch June 15, 2023 14:17
@cdce8p
Copy link
Collaborator Author

cdce8p commented Jun 15, 2023

I've been wondering: why don't we use dataclasses?

Might also be that "normal" classes are already quite optimized with mypyc, not sure about that though. Would certainly require some more analysis.

@cdce8p
Copy link
Collaborator Author

cdce8p commented Jun 15, 2023

Could someone add the topic-pep-696 label here as well? That would make it easier to keep track.

@AlexWaygood AlexWaygood added the topic-pep-696 TypeVar defaults label Jun 15, 2023
@AlexWaygood
Copy link
Member

Could someone add the topic-pep-696 label here as well? That would make it easier to keep track.

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-pep-696 TypeVar defaults
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants