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

PEP 634: Allow keyword patterns for int, str etc. #1908

Merged
merged 1 commit into from
Apr 5, 2021
Merged

Conversation

gvanrossum
Copy link
Member

@gvanrossum gvanrossum commented Apr 3, 2021

This resolves a discrepancy between the specification and the implementation, in favor of the current implementation. The spec used to state that you can't have patterns like these:

    case int(x, real=0): ...
    case int(real=1): ...

The implementation allows this and there is no good reason to disallow it, so it makes sense to rule that the PEP was mistaken here. (I don't recall why I put it in the PEP and in fact I was surprised to find it there.)

@gvanrossum
Copy link
Member Author

@gvanrossum gvanrossum changed the title Allow keyword patterns for int, str etc. PEP 634: Allow keyword patterns for int, str etc. Apr 3, 2021
Copy link
Contributor

@willingc willingc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying.

@gvanrossum
Copy link
Member Author

@brandtbucher -- What do you think? The implementation already does this, so it's just a matter of aligning the PEP with the implementation. I don't see any reason to disallow keywords for these types.

Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this is better. I wasn't aware that the restriction was in the PEP when we submitted it (and would have tried to remove it if so)!

@gvanrossum gvanrossum requested a review from brettcannon April 5, 2021 17:38
@gvanrossum
Copy link
Member Author

I think this is now sufficiently non-controversial that I'm just changing the PEP. Adding @brettcannon so the SC isn't caught by surprise that we're making this change.

@gvanrossum gvanrossum merged commit d196748 into master Apr 5, 2021
@gvanrossum gvanrossum deleted the tweak-pep-634 branch April 5, 2021 17:39
gvanrossum pushed a commit to python/cpython that referenced this pull request Apr 6, 2021
See:
- python/peps#1909 (__match_args__ must be a tuple)
- python/peps#1908 (allow keyword patterns for int(x) etc.)
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.

4 participants