You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Spurious errors on the builtin open when running mypy on mypy #14796
When running mypy following the procedure below, I encounter several errors for the overloaded open builtin of the form:
../python3.11/site-packages/mypy/typeshed/stdlib/builtins.pyi:1327: error: Argument 8 to "open" becomes "Optional[Any]" due to an unfollowed import [no-any-unimported]
To reproduce:
Set up a virtualenv with Python 3.11 and activate it.
Both --no-silence-site-packages and --disallow-any-unimported need to be present.
Version 1.0.0 of mypy is required. Older versions don't exhibit this error.
This is the simplest way we have found to reproduce this problem, but we first encountered it in one of our own projects.
The issue is being filed here because the mypy docs for reporting bugs says that problems with a specific library function should be reported here. We're not seeing this error with any other functions.
I suspect that this issue may be caused by a cyclic import between typing_extensions and builtins. If I apply this diff to builtins.pyi in site-packages/mypy/typeshed, then the error goes away:
I think the best thing to do would be to revert 6442b02. It fixes the crash that it was meant to fix, but I get some very strange mypy errors if I try changing builtins.pyi in typeshed so that it imports things from collections.abc instead of typing, so something is clearly going wrong there. Plus the crash is very typeshed-specific, so it's not really high-priority.
Activity
AlexWaygood commentedon Feb 27, 2023
Interesting. I can reproduce this.
For reference argument 8 of
builtins.openis this:https://github.com/python/typeshed/blob/9b63a49f6419bc7a04cf0d2be0433c255f1b1852/stdlib/builtins.pyi#L1500
And the
_Openertype alias is defined inbuiltins.pyihere:https://github.com/python/typeshed/blob/9b63a49f6419bc7a04cf0d2be0433c255f1b1852/stdlib/builtins.pyi#L1488
I suspect that this issue may be caused by a cyclic import between
typing_extensionsandbuiltins. If I apply this diff tobuiltins.pyiinsite-packages/mypy/typeshed, then the error goes away:AlexWaygood commentedon Feb 27, 2023
This bisects to 6442b02: I can reproduce with 6442b02 checked out locally, but not with 0665ce9.
AlexWaygood commentedon Feb 27, 2023
@JelleZijlstra or @hauntsaninja, could one of you transfer this issue to mypy?
I think the best thing to do would be to revert 6442b02. It fixes the crash that it was meant to fix, but I get some very strange mypy errors if I try changing
builtins.pyiin typeshed so that it imports things fromcollections.abcinstead oftyping, so something is clearly going wrong there. Plus the crash is very typeshed-specific, so it's not really high-priority.Unfortunately it's not a clean revert.
AlexWaygood commentedon Feb 27, 2023
Cc. @Michael0x2a as author of the commit that this bisects to
Fix spurious errors on builtins.open
Fix spurious errors on builtins.open (#15161)
hauntsaninja commentedon Jun 24, 2023
Re-opening since I reverted #15161 because it was causing further typeshed issues