microsoft / pyright

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

Changed behavior for protocols that have methods with method-scoped t… #8751

Closed erictraut closed 1 month ago

erictraut commented 1 month ago

…ype variables. These are no longer treated as free type variables during protocol matching, so they can be used to support rank-2 polymorphism. This behavior is not currently dictated by the typing spec, but it is more consistent with mypy. This addresses #8685.

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)
+         Function return type "Literal[1]" is incompatible with type "DataFrameOrSeriesLike_@__call__"
+           Type "Literal[1]" is incompatible with type "DataFrameOrSeriesLike_@__call__"
-         Function accepts too many positional parameters; expected 0 but received 2
-       Type "() -> Literal[1]" is incompatible with type "(Unknown, Unknown, Unknown) -> Unknown"
+         Function return type "Literal[1]" is incompatible with type "DataFrameOrSeriesLike_@__call__"
+           Type "Literal[1]" is incompatible with type "DataFrameOrSeriesLike_@__call__"
-       Type "() -> Literal[1]" is incompatible with type "(Unknown, Unknown) -> Unknown"
-         Function accepts too many positional parameters; expected 0 but received 2
-       Type "() -> Literal[1]" is incompatible with type "(Unknown, Unknown, Unknown) -> Unknown" (reportArgumentType)
+       Type "() -> Literal[1]" is incompatible with type "(Unknown, Unknown) -> Unknown" (reportArgumentType)

trio (https://github.com/python-trio/trio)
-   /tmp/mypy_primer/projects/trio/src/trio/_core/_ki.py:199:81 - error: Unnecessary "# type: ignore" comment (reportUnnecessaryTypeIgnoreComment)
-   /tmp/mypy_primer/projects/trio/src/trio/_core/_ki.py:202:83 - error: Unnecessary "# type: ignore" comment (reportUnnecessaryTypeIgnoreComment)
- 3870 errors, 53 warnings, 0 informations 
+ 3868 errors, 53 warnings, 0 informations 

pwndbg (https://github.com/pwndbg/pwndbg)
+   /tmp/mypy_primer/projects/pwndbg/pwndbg/commands/cymbol.py:84:12 - error: Expression of type "_Wrapped[(custom_structure_name: str, custom_structure_path: str = ...), T@__call__ | None, (custom_structure_name: str, custom_structure_path: str = ...), T@wrapper | None]" is incompatible with return type "_OnlyWhenStructFileExists"
+     "_Wrapped[(custom_structure_name: str, custom_structure_path: str = ...), T@__call__ | None, (custom_structure_name: str, custom_structure_path: str = ...), T@wrapper | None]" is incompatible with protocol "_OnlyWhenStructFileExists"
+       "__call__" is an incompatible type
+         Type "(custom_structure_name: str, custom_structure_path: str = ...) -> (T@wrapper | None)" is incompatible with type "(custom_structure_name: str, custom_structure_path: str = "") -> (T@__call__ | None)"
+           Function return type "T@wrapper | None" is incompatible with type "T@__call__ | None" (reportReturnType)
-       Parameter "y" is missing default argument (reportArgumentType)
+       Parameter "y" is missing default argument
+       Function return type "Literal[True]" is incompatible with type "T@__call__ | None"
+         Type "Literal[True]" is incompatible with type "T@__call__ | None"
+           Type "Literal[True]" is incompatible with type "T@__call__"
+           "Literal[True]" is incompatible with "None" (reportArgumentType)
-       Parameter "y" is missing default argument (reportArgumentType)
+       Parameter "y" is missing default argument
+       Function return type "Literal[True]" is incompatible with type "T@__call__ | None"
+         Type "Literal[True]" is incompatible with type "T@__call__ | None"
+           Type "Literal[True]" is incompatible with type "T@__call__"
+           "Literal[True]" is incompatible with "None" (reportArgumentType)
- 1947 errors, 188 warnings, 0 informations 
+ 1948 errors, 188 warnings, 0 informations