◐ Shell
reader mode source ↗
Skip to content

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

Merged
gvanrossum merged 1 commit into
masterfrom
tweak-pep-634
Apr 5, 2021
Merged

PEP 634: Allow keyword patterns for int, str etc.#1908
gvanrossum merged 1 commit into
masterfrom
tweak-pep-634

Conversation

@gvanrossum

@gvanrossum gvanrossum commented Apr 3, 2021

Copy link
Copy Markdown
Member

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
Copy Markdown
Member Author

@gvanrossum gvanrossum changed the title Allow keyword patterns for int, str etc. Apr 3, 2021

@willingc willingc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hide comment

Thanks for clarifying.

@gvanrossum

Copy link
Copy Markdown
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.

@brandtbucher brandtbucher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hide comment

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