-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
bpo-38008: Move builtin protocol whitelist to mapping instead of list #15647
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Our records indicate we have not received your CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for your contribution, we look forward to reviewing it! |
Lib/typing.py
Outdated
'Hashable', 'Sized', 'Container', 'Collection', 'Reversible', | ||
'ContextManager', 'AsyncContextManager'] | ||
_PROTO_WHITELIST = { | ||
'Callable': 'collections.abc', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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__]
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
Lib/typing.py
Outdated
'Hashable', 'Sized', 'Container', 'Collection', 'Reversible', | ||
'ContextManager', 'AsyncContextManager'] | ||
_PROTO_WHITELIST = { | ||
'Callable': 'collections.abc', |
There was a problem hiding this comment.
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__]
There was a problem hiding this comment.
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.)
Thanks @ilevkivskyi, didn't know about that! |
Thanks @jivid for the PR, and @ilevkivskyi for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8. |
…pythonGH-15647) Fixes https://bugs.python.org/issue38008 (cherry picked from commit 692a0dc) Co-authored-by: Divij Rajkumar <[email protected]>
GH-16021 is a backport of this pull request to the 3.8 branch. |
…GH-15647) Fixes https://bugs.python.org/issue38008 (cherry picked from commit 692a0dc) Co-authored-by: Divij Rajkumar <[email protected]>
and rename _PROTO_WHITELIST to _PROTO_ALLOWLIST taken from python/cpython#15647 and python/cpython#21825
taken from python/cpython#15647 and python/cpython#21823
https://bugs.python.org/issue38008
https://bugs.python.org/issue38008