microsoft / pyright

Static Type Checker for Python
Other
13.12k stars 1.4k forks source link

Fixed a bug that results in incorrect type narrowing when using `isin… #8675

Closed erictraut closed 1 month ago

erictraut commented 1 month ago

…stance` with an instance of a generic class as the first argument and a concrete subclass as the filter type. This addresses #8672.

github-actions[bot] commented 1 month ago

Diff from mypy_primer, showing the effect of this PR on open source code:

spark (https://github.com/apache/spark)
+   /tmp/mypy_primer/projects/spark/python/pyspark/pandas/window.py:980:16 - error: Expression of type "FrameLike@RollingGroupby | DataFrame[Unknown]" is incompatible with return type "FrameLike@RollingGroupby"
+     Type "FrameLike@RollingGroupby | DataFrame[Unknown]" is incompatible with type "FrameLike@RollingGroupby" (reportReturnType)
- 24178 errors, 279 warnings, 0 informations 
+ 24179 errors, 279 warnings, 0 informations 

aioredis (https://github.com/aio-libs/aioredis)
+   /tmp/mypy_primer/projects/aioredis/aioredis/client.py:99:25 - error: Expression of type "list[str]" is incompatible with declared type "List[_KeyT@list_or_args | _ArgT@list_or_args]"
+     Type "str" is incompatible with type "_KeyT@list_or_args | _ArgT@list_or_args"
+       Type "str" is incompatible with type "_ArgT@list_or_args"
+       Type "str" is incompatible with type "_KeyT@list_or_args" (reportAssignmentType)
- 63 errors, 0 warnings, 0 informations 
+ 64 errors, 0 warnings, 0 informations 

streamlit (https://github.com/streamlit/streamlit)
+   /tmp/mypy_primer/projects/streamlit/lib/streamlit/dataframe_util.py:635:16 - error: Expression of type "list[int | str | V_co@convert_anything_to_sequence]" is incompatible with return type "Sequence[V_co@convert_anything_to_sequence]"
+     "list[int | str | V_co@convert_anything_to_sequence]" is incompatible with "Sequence[V_co@convert_anything_to_sequence]"
+       Type parameter "_T_co@Sequence" is covariant, but "int | str | V_co@convert_anything_to_sequence" is not a subtype of "V_co@convert_anything_to_sequence"
+         Type "int | str | V_co@convert_anything_to_sequence" is incompatible with type "V_co@convert_anything_to_sequence" (reportReturnType)
- 3423 errors, 144 warnings, 0 informations 
+ 3424 errors, 144 warnings, 0 informations