bpo-38008: Move builtin protocol whitelist to mapping instead of list by jivid · Pull Request #15647 · python/cpython · GitHub
Skip to content

bpo-38008: Move builtin protocol whitelist to mapping instead of list - #15647

Merged
ilevkivskyi merged 3 commits into
python:masterfrom
jivid:fix-issue-38008
Sep 12, 2019
Merged

ilevkivskyi merged 3 commits into
python:masterfrom
jivid:fix-issue-38008

Conversation

@jivid

@jivid jivid commented Sep 2, 2019

Copy link
Copy Markdown
Contributor

@the-knights-who-say-ni

Copy link
Copy Markdown

Comment thread Lib/typing.py Outdated
'Hashable', 'Sized', 'Container', 'Collection', 'Reversible',
'ContextManager', 'AsyncContextManager']
_PROTO_WHITELIST = {
'Callable': 'collections.abc',

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.

I'd like to write code in this way.
'Callable': collections.abc.__name__,
It can catch typo error.

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.

Alternatively I would just avoid the repetition by making _PROTO_WHITELIST a dictionary mapping module to set of names in it. So that the code below would be

    base.__module__ in _PROTO_WHITELIST and
    base.__name__ in _PROTO_WHITELIST[base.__module__]

@corona10 corona10 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.

Please add news entries by using blurb tool.

https://devguide.python.org/committing/#what-s-new-and-news-entries

@ilevkivskyi ilevkivskyi 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.

Thanks for PR!

I have just one suggestion, could you please add some tests? (and a news entry as @corona10 suggested)

Comment thread Lib/typing.py Outdated
'Hashable', 'Sized', 'Container', 'Collection', 'Reversible',
'ContextManager', 'AsyncContextManager']
_PROTO_WHITELIST = {
'Callable': 'collections.abc',

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.

Alternatively I would just avoid the repetition by making _PROTO_WHITELIST a dictionary mapping module to set of names in it. So that the code below would be

    base.__module__ in _PROTO_WHITELIST and
    base.__name__ in _PROTO_WHITELIST[base.__module__]

@ilevkivskyi ilevkivskyi 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.

Thanks, LGTM!

(Also there is a tool called blurb, so that you don't need to create the news items manually.)

@jivid

jivid commented Sep 12, 2019

Copy link
Copy Markdown
Contributor Author

Thanks @ilevkivskyi, didn't know about that!

@ilevkivskyi ilevkivskyi added needs backport to 3.8 type-bug An unexpected behavior, bug, or error labels Sep 12, 2019
@ilevkivskyi
ilevkivskyi merged commit 692a0dc into python:master Sep 12, 2019
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @jivid for the PR, and @ilevkivskyi for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 12, 2019
…pythonGH-15647)

Fixes https://bugs.python.org/issue38008
(cherry picked from commit 692a0dc)

Co-authored-by: Divij Rajkumar <drajkuma1@gmail.com>
@bedevere-bot

Copy link
Copy Markdown

miss-islington added a commit that referenced this pull request Sep 12, 2019
…GH-15647)

Fixes https://bugs.python.org/issue38008
(cherry picked from commit 692a0dc)

Co-authored-by: Divij Rajkumar <drajkuma1@gmail.com>
YouJiacheng added a commit to YouJiacheng/typing_extensions that referenced this pull request Mar 28, 2023
and rename _PROTO_WHITELIST to _PROTO_ALLOWLIST

taken from python/cpython#15647 and python/cpython#21825
YouJiacheng added a commit to YouJiacheng/typing_extensions that referenced this pull request Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants