Open gmc444-b opened 1 year ago
Interesting. I can reproduce this.
For reference argument 8 of builtins.open
is this:
And the _Opener
type alias is defined in builtins.pyi
here:
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:
--- a/stdlib/builtins.pyi
+++ b/stdlib/builtins.pyi
@@ -1485,7 +1485,7 @@ def next(__i: SupportsNext[_T]) -> _T: ...
def next(__i: SupportsNext[_T], __default: _VT) -> _T | _VT: ...
def oct(__number: int | SupportsIndex) -> str: ...
-_Opener: TypeAlias = Callable[[str, int], int]
+_Opener = Callable[[str, int], int]
This bisects to https://github.com/python/mypy/commit/6442b02400ac6e6715247d29ea2d3da8ca8e35d8: I can reproduce with https://github.com/python/mypy/commit/6442b02400ac6e6715247d29ea2d3da8ca8e35d8 checked out locally, but not with https://github.com/python/mypy/commit/0665ce924290dad3f30010b3bb93310a71c8db81.
@JelleZijlstra or @hauntsaninja, could one of you transfer this issue to mypy?
I think the best thing to do would be to revert https://github.com/python/mypy/commit/6442b02400ac6e6715247d29ea2d3da8ca8e35d8. 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.
Unfortunately it's not a clean revert.
Cc. @Michael0x2a as author of the commit that this bisects to
Re-opening since I reverted #15161 because it was causing further typeshed issues
When running
mypy
following the procedure below, I encounter several errors for the overloadedopen
builtin of the form:To reproduce:
pip install mypy
python-m mypy --strict --no-silence-site-packages --disallow-any-unimported -m mypy
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.