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

mypy resolves symbol incorrectly with builtins import cycle #11535

Open
hauntsaninja opened this issue Nov 13, 2021 · 0 comments
Open

mypy resolves symbol incorrectly with builtins import cycle #11535

hauntsaninja opened this issue Nov 13, 2021 · 0 comments
Labels
bug mypy got something wrong topic-import-cycles

Comments

@hauntsaninja
Copy link
Collaborator

Context: python/typeshed#6289

To reproduce:

  1. check out typeshed
  2. git checkout 9eabedca5f47a710f29d6e3e2b3a389853fab5aa
  3. apply this patch
diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi
index 2393f3c9..0d2ea882 100644
--- a/stdlib/builtins.pyi
+++ b/stdlib/builtins.pyi
@@ -717,6 +717,7 @@ class bool(int):
     def __rxor__(self, __x: int) -> int: ...
     def __getnewargs__(self) -> tuple[int]: ...
 
+@final
 class slice(object):
     start: Any
     step: Any

Then run:

mypy --python-version 3.10 --no-incremental --custom-typeshed-dir . stdlib/_ast.pyi stdlib/ast.pyi 

and note that mypy incorrectly resolves slice to builtins.slice instead of ast.slice in ast.pyi

Note that if you change the order of files, it works just fine:

mypy --python-version 3.10 --no-incremental --custom-typeshed-dir . stdlib/ast.pyi stdlib/_ast.pyi 

It's a pretty weird case, import cycle with builtins, collision with name in builtins, from _ast import * in ast.pyi, etc. But a scary kind of bug :-)

@hauntsaninja hauntsaninja added the bug mypy got something wrong label Nov 13, 2021
@hauntsaninja hauntsaninja changed the title mypy resolves symbol incorrectly with import cycle mypy resolves symbol incorrectly with builtins import cycle Nov 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-import-cycles
Projects
None yet
Development

No branches or pull requests

2 participants