Skip to content

fix: do not crash if "_" is parsed in builtins #11811

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

Merged
merged 1 commit into from
Dec 21, 2021

Conversation

StefanM-TT
Copy link
Contributor

allows the definiton of "_" as function in builtins (e.g via typeshed).

fixes issue #9802

Description

Fixes #9802

Test Plan

allows the definiton of "_" as function in builtins (e.g via typeshed).

fixes issue python#9802
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Can you please also add a test case to make sure that this feature works as intended? 🙂

@@ -4296,7 +4296,7 @@ def lookup(self, name: str, ctx: Context,
assert isinstance(b.node, MypyFile)
table = b.node.names
if name in table:
if name[0] == "_" and name[1] != "_":
if len(name) > 1 and name[0] == "_" and name[1] != "_":
Copy link
Member

Choose a reason for hiding this comment

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

Question: why would we need to define _ as a function in __builtins__? There's no such function as far as I remember.

The original issue was about a custom module, not __builtins__.

Copy link
Member

Choose a reason for hiding this comment

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

@hauntsaninja hauntsaninja merged commit 9d5ef72 into python:master Dec 21, 2021
@hauntsaninja
Copy link
Collaborator

Thank you!

(I was happy to merge without a dedicated test, not really worth a custom builtins stub)

tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this pull request Jan 20, 2022
allows the definition of "_" as function in builtins (e.g via typeshed).

fixes python#9802
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't use _ in typeshed
4 participants