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
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 Union[os.DirEntry[Any], Any] and Example 2 as Any. After debugging some more I discovered that only TypeVar bounds, and not the list, are considered in the below case, which ends up deciding the TypeVar constraints for the call.
Activity
JelleZijlstra commentedon Jan 10, 2022
For what it's worth, the only significant recent change to the stubs for scandir was to use
|syntax: https://github.com/python/typeshed/blame/master/stdlib/os/__init__.pyi#L711ktbarrett commentedon Jan 10, 2022
@achimnol Are you certain the original code is valid? typeshed does not mention that
os.scandirtakes aos.DirEntry.JelleZijlstra commentedon Jan 10, 2022
@ktbarrett
DirEntryis anos.PathLike.ktbarrett commentedon Jan 10, 2022
The change from
Unionto|did not affect anything. Confirmed it broke in 0.920.Changing the signature of scandir to the following works.
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.
ktbarrett commentedon Jan 10, 2022
git bisectshows 7808e82 (#10887).ktbarrett commentedon Jan 11, 2022
Started debugging a simpler example against the passing example below it that uses a Union bound instead of a list.
Fails:
Passes:
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
Union[os.DirEntry[Any], Any]and Example 2 asAny. After debugging some more I discovered that only TypeVar bounds, and not the list, are considered in the below case, which ends up deciding the TypeVar constraints for the call.mypy/mypy/constraints.py
Lines 198 to 202 in 48d810d
achimnol commentedon Feb 16, 2022
How is this going? Just checking in. 😉
ktbarrett commentedon Feb 16, 2022
I spent a couple hours looking into it and I think it's due to a lack of support for type lists in
infer_constraints. It's not a trivial fix.