-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Regression of os.scandir() typecheck #11964
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
Comments
For what it's worth, the only significant recent change to the stubs for scandir was to use |
@achimnol Are you certain the original code is valid? typeshed does not mention that |
@ktbarrett |
The change from Changing the signature of scandir to the following works. @overload
def scandir(path: str | PathLike[str]]) -> _ScandirIterator[str]: ...
@overload
def scandir(path: bytes | PathLike[bytes]) -> _ScandirIterator[bytes]: ... Changing the signature of AnyStr to use a Union bound also works. So the problem must be with how listed types are checked between 0.910 and 0.920. |
Started debugging a simpler example against the passing example below it that uses a Union bound instead of a list. Fails: a: os.DirEntry[Any]
os.scandir(a) Passes: from typing import *
import os
MyAnyStr = TypeVar("MyAnyStr", bound=Union[bytes, str])
MyAnyStr_co = TypeVar("MyAnyStr_co", bound=Union[bytes, str], covariant=True)
class MyPathLike(Protocol[MyAnyStr_co]):
def __fspath__(self) -> MyAnyStr_co: ...
def wew(t: Union[MyAnyStr, MyPathLike[MyAnyStr]]) -> None:
...
test: os.DirEntry
wew(test) After much debugging (which is not easy at all because of how coarse-grained the switch on incremental compile is) I found that the difference was in how the type variable was inferred. Example 1 inferred the TypeVar as Lines 198 to 202 in 48d810d
|
How is this going? Just checking in. 😉 |
I spent a couple hours looking into it and I think it's due to a lack of support for type lists in |
Bug Report
Type variable inference related with
os.scandir()
seems to generate false-positives.To Reproduce
Here is a minimal reproduction example, which is accepted by mypy 0.910 but rejected by 0.930 and 0.931.
Expected Behavior
Actual Behavior
Your Environment
python -m mypy test.py
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: