Skip to content
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

Fixed bug that results in a spurious "incompatible method override" e… #9700

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

erictraut
Copy link
Collaborator

…rror when two subclasses with an overloaded method are combined using multiple inheritance. This addresses #9625.

…rror when two subclasses with an overloaded method are combined using multiple inheritance. This addresses #9625.
Copy link
Contributor

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

pyodide (https://github.com/pyodide/pyodide)
+   /tmp/mypy_primer/projects/pyodide/src/py/_pyodide/_core_docs.py:1078:7 - error: Base classes for class "JsMutableMap" define method "get" in incompatible way
+     Override does not handle all overloads of base method (reportIncompatibleMethodOverride)
- 748 errors, 14 warnings, 0 informations 
+ 749 errors, 14 warnings, 0 informations 

ibis (https://github.com/ibis-project/ibis)
+   /tmp/mypy_primer/projects/ibis/ibis/common/collections.py:280:7 - error: Base classes for class "FrozenDict" define method "get" in incompatible way
+     No overload signature in override is compatible with base method (reportIncompatibleMethodOverride)
- 7343 errors, 126 warnings, 0 informations 
+ 7344 errors, 126 warnings, 0 informations 

sympy (https://github.com/sympy/sympy)
+     Override does not handle all overloads of base method (reportIncompatibleMethodOverride)
-     Parameter 2 type mismatch: base parameter is type "Iterable[tuple[Basic | complex, Basic | complex]]", override parameter is type "Mapping[Basic | complex, Basic | complex] | Basic | complex"
-       Type "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to type "Mapping[Basic | complex, Basic | complex] | Basic | complex"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "Mapping[Basic | complex, Basic | complex]"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "Basic"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "complex" (reportIncompatibleMethodOverride)
+     Override does not handle all overloads of base method (reportIncompatibleMethodOverride)
-     Parameter 2 type mismatch: base parameter is type "Iterable[tuple[Basic | complex, Basic | complex]]", override parameter is type "Mapping[Basic | complex, Basic | complex] | Basic | complex"
-       Type "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to type "Mapping[Basic | complex, Basic | complex] | Basic | complex"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "Mapping[Basic | complex, Basic | complex]"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "Basic"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "complex" (reportIncompatibleMethodOverride)
+     Override does not handle all overloads of base method (reportIncompatibleMethodOverride)
-     Parameter 2 type mismatch: base parameter is type "Iterable[tuple[Basic | complex, Basic | complex]]", override parameter is type "Mapping[Basic | complex, Basic | complex] | Basic | complex"
-       Type "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to type "Mapping[Basic | complex, Basic | complex] | Basic | complex"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "Mapping[Basic | complex, Basic | complex]"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "Basic"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "complex" (reportIncompatibleMethodOverride)
+     Override does not handle all overloads of base method (reportIncompatibleMethodOverride)
-     Parameter 2 type mismatch: base parameter is type "Iterable[tuple[Basic | complex, Basic | complex]]", override parameter is type "Mapping[Basic | complex, Basic | complex] | Basic | complex"
-       Type "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to type "Mapping[Basic | complex, Basic | complex] | Basic | complex"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "Mapping[Basic | complex, Basic | complex]"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "Basic"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "complex" (reportIncompatibleMethodOverride)
+     Override does not handle all overloads of base method (reportIncompatibleMethodOverride)
-     Parameter 2 type mismatch: base parameter is type "Iterable[tuple[Basic | complex, Basic | complex]]", override parameter is type "Mapping[Basic | complex, Basic | complex] | Basic | complex"
-       Type "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to type "Mapping[Basic | complex, Basic | complex] | Basic | complex"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "Mapping[Basic | complex, Basic | complex]"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "Basic"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "complex" (reportIncompatibleMethodOverride)
+     Override does not handle all overloads of base method (reportIncompatibleMethodOverride)
-     Parameter 2 type mismatch: base parameter is type "Iterable[tuple[Basic | complex, Basic | complex]]", override parameter is type "Mapping[Basic | complex, Basic | complex] | Basic | complex"
-       Type "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to type "Mapping[Basic | complex, Basic | complex] | Basic | complex"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "Mapping[Basic | complex, Basic | complex]"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "Basic"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "complex" (reportIncompatibleMethodOverride)
+     Override does not handle all overloads of base method (reportIncompatibleMethodOverride)
-     Parameter 2 type mismatch: base parameter is type "Iterable[tuple[Basic | complex, Basic | complex]]", override parameter is type "Mapping[Basic | complex, Basic | complex] | Basic | complex"
-       Type "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to type "Mapping[Basic | complex, Basic | complex] | Basic | complex"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "Mapping[Basic | complex, Basic | complex]"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "Basic"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "complex" (reportIncompatibleMethodOverride)
+     Override does not handle all overloads of base method (reportIncompatibleMethodOverride)
-     Parameter 2 type mismatch: base parameter is type "Iterable[tuple[Basic | complex, Basic | complex]]", override parameter is type "Mapping[Basic | complex, Basic | complex] | Basic | complex"
-       Type "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to type "Mapping[Basic | complex, Basic | complex] | Basic | complex"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "Mapping[Basic | complex, Basic | complex]"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "Basic"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "complex" (reportIncompatibleMethodOverride)
+     Override does not handle all overloads of base method (reportIncompatibleMethodOverride)
-     Parameter 2 type mismatch: base parameter is type "Iterable[tuple[Basic | complex, Basic | complex]]", override parameter is type "Mapping[Basic | complex, Basic | complex] | Basic | complex"
-       Type "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to type "Mapping[Basic | complex, Basic | complex] | Basic | complex"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "Mapping[Basic | complex, Basic | complex]"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "Basic"
-         "Iterable[tuple[Basic | complex, Basic | complex]]" is not assignable to "complex" (reportIncompatibleMethodOverride)
-   /tmp/mypy_primer/projects/sympy/sympy/utilities/matchpy_connector.py:288:16 - error: Type "Basic" is not assignable to declared type "Expr"
-     "Basic" is not assignable to "Expr" (reportAssignmentType)
-   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_matchpy_connector.py:120:18 - error: Argument of type "Equality | Unknown" cannot be assigned to parameter "expr" of type "Expr" in function "add"
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_matchpy_connector.py:120:18 - error: Argument of type "Equality | Unknown | Relational | Unequality | Integer" cannot be assigned to parameter "expr" of type "Expr" in function "add"
-     Type "Equality | Unknown" is not assignable to type "Expr"
+     Type "Equality | Unknown | Relational | Unequality | Integer" is not assignable to type "Expr"
-       "Equality" is not assignable to "Expr" (reportArgumentType)
+       "Relational" is not assignable to "Expr" (reportArgumentType)
-   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_matchpy_connector.py:123:18 - error: Argument of type "Equality | Unknown" cannot be assigned to parameter "expr" of type "Expr" in function "add"
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_matchpy_connector.py:123:18 - error: Argument of type "Equality | Unknown | Relational | Unequality | Integer" cannot be assigned to parameter "expr" of type "Expr" in function "add"
-     Type "Equality | Unknown" is not assignable to type "Expr"
+     Type "Equality | Unknown | Relational | Unequality | Integer" is not assignable to type "Expr"
-       "Equality" is not assignable to "Expr" (reportArgumentType)
+       "Relational" is not assignable to "Expr" (reportArgumentType)
-   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_matchpy_connector.py:126:9 - error: Argument of type "Equality | Unknown" cannot be assigned to parameter "expr" of type "Expr" in function "add"
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_matchpy_connector.py:126:9 - error: Argument of type "Equality | Unknown | Relational | Unequality | Integer" cannot be assigned to parameter "expr" of type "Expr" in function "add"
-     Type "Equality | Unknown" is not assignable to type "Expr"
+     Type "Equality | Unknown | Relational | Unequality | Integer" is not assignable to type "Expr"
-       "Equality" is not assignable to "Expr" (reportArgumentType)
+       "Relational" is not assignable to "Expr" (reportArgumentType)
-   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_matchpy_connector.py:132:9 - error: Argument of type "Equality | Unknown" cannot be assigned to parameter "expr" of type "Expr" in function "add"

... (truncated 122 lines) ...

pydantic (https://github.com/pydantic/pydantic)
+   /tmp/mypy_primer/projects/pydantic/pydantic/_internal/_generics.py:39:11 - error: Base classes for class "LimitedDict" define method "get" in incompatible way
+     Override does not handle all overloads of base method (reportIncompatibleMethodOverride)
+   /tmp/mypy_primer/projects/pydantic/pydantic/_internal/_generics.py:39:11 - error: Base classes for class "LimitedDict" define method "pop" in incompatible way
+     Override does not handle all overloads of base method (reportIncompatibleMethodOverride)
- 263 errors, 45 warnings, 0 informations 
+ 265 errors, 45 warnings, 0 informations 

mkdocs (https://github.com/mkdocs/mkdocs)
+   /tmp/mypy_primer/projects/mkdocs/mkdocs/plugins.py:493:7 - error: Base classes for class "PluginCollection" define method "get" in incompatible way
+     Override does not handle all overloads of base method (reportIncompatibleMethodOverride)
+   /tmp/mypy_primer/projects/mkdocs/mkdocs/plugins.py:493:7 - error: Base classes for class "PluginCollection" define method "pop" in incompatible way
+     Override does not handle all overloads of base method (reportIncompatibleMethodOverride)
- 197 errors, 23 warnings, 0 informations 
+ 199 errors, 23 warnings, 0 informations 

xarray (https://github.com/pydata/xarray)
-   /tmp/mypy_primer/projects/xarray/xarray/core/variable.py:371:7 - error: Base classes for class "Variable" define method "get_axis_num" in incompatible way
-     Return type mismatch: base method returns type "int", override returns type "int | tuple[int, ...]"
-       Type "int | tuple[int, ...]" is not assignable to type "int"
-         "tuple[int, ...]" is not assignable to "int" (reportIncompatibleMethodOverride)
- 2470 errors, 91 warnings, 0 informations 
+ 2469 errors, 91 warnings, 0 informations 

websockets (https://github.com/aaugustin/websockets)
+   /tmp/mypy_primer/projects/websockets/tests/asyncio/test_connection.py:31:7 - error: Base classes for class "ClientConnectionTests" define method "assertNoLogs" in incompatible way
+     Return type mismatch: base method returns type "_AssertLogsContext[None]", override returns type "_GeneratorContextManager[None]"
+       "_GeneratorContextManager[None]" is not assignable to "_AssertLogsContext[None]" (reportIncompatibleMethodOverride)
+   /tmp/mypy_primer/projects/websockets/tests/asyncio/test_server.py:36:7 - error: Base classes for class "ServerTests" define method "assertNoLogs" in incompatible way
+     Return type mismatch: base method returns type "_AssertLogsContext[None]", override returns type "_GeneratorContextManager[None]"
+       "_GeneratorContextManager[None]" is not assignable to "_AssertLogsContext[None]" (reportIncompatibleMethodOverride)
+ /tmp/mypy_primer/projects/websockets/tests/legacy/utils.py
+   /tmp/mypy_primer/projects/websockets/tests/legacy/utils.py:9:7 - error: Base classes for class "AsyncioTestCase" define method "assertNoLogs" in incompatible way
+     Return type mismatch: base method returns type "_AssertLogsContext[None]", override returns type "_GeneratorContextManager[None]"
+       "_GeneratorContextManager[None]" is not assignable to "_AssertLogsContext[None]" (reportIncompatibleMethodOverride)
- 977 errors, 15 warnings, 0 informations 
+ 980 errors, 15 warnings, 0 informations 

@erictraut erictraut merged commit 1593a7c into main Jan 14, 2025
18 checks passed
@erictraut erictraut deleted the issue-9625 branch January 14, 2025 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant