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 a bug that causes a false positive error when a class uses `typ… #9355

Closed
wants to merge 1 commit into from

Conversation

erictraut
Copy link
Collaborator

…e(Protocol)` as a base class. This addresses #9217.

This fix involves a change to the internal isSameGenericClass method, which was previously too permissive. This change required dozens of downstream changes, and it has a high risk of regression.

…e(Protocol)` as a base class. This addresses #9217.

This fix involves a change to the internal isSameGenericClass method, which was previously too permissive. This change required dozens of downstream changes, and it has a high risk of regression.
Copy link
Contributor

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

steam.py (https://github.com/Gobot1234/steam.py)
+   /tmp/mypy_primer/projects/steam.py/steam/event.py:251:34 - error: Condition will always evaluate to True since the types "App[str | None]" and "None" have no overlap (reportUnnecessaryComparison)
- 8443 errors, 95 warnings, 0 informations 
+ 8444 errors, 95 warnings, 0 informations 

sympy (https://github.com/sympy/sympy)
-   /tmp/mypy_primer/projects/sympy/sympy/physics/quantum/operatorset.py:218:34 - error: Argument of type "type[StateBase]" cannot be assigned to parameter "key" of type "type[JxKet] | type[JyKet] | type[JzKet] | type[Ket] | type[PositionKet3D] | type[PxKet] | type[XKet]" in function "__getitem__"
+   /tmp/mypy_primer/projects/sympy/sympy/physics/quantum/operatorset.py:218:34 - error: Argument of type "type[StateBase] | type[type[StateBase]]" cannot be assigned to parameter "key" of type "type[JxKet] | type[JyKet] | type[JzKet] | type[Ket] | type[PositionKet3D] | type[PxKet] | type[XKet]" in function "__getitem__"
+     Type "type[StateBase] | type[type[StateBase]]" is not assignable to type "type[JxKet] | type[JyKet] | type[JzKet] | type[Ket] | type[PositionKet3D] | type[PxKet] | type[XKet]"
-     Type "type[StateBase]" is not assignable to type "type[JxKet] | type[JyKet] | type[JzKet] | type[Ket] | type[PositionKet3D] | type[PxKet] | type[XKet]"
+       Type "type[StateBase]" is not assignable to type "type[JxKet] | type[JyKet] | type[JzKet] | type[Ket] | type[PositionKet3D] | type[PxKet] | type[XKet]"
-       "type[StateBase]" is not assignable to "type[JxKet]"
+         "type[StateBase]" is not assignable to "type[JxKet]"
-       Type "type[StateBase]" is not assignable to type "type[JxKet]"
+         Type "type[StateBase]" is not assignable to type "type[JxKet]"
-       "type[StateBase]" is not assignable to "type[JyKet]"
+         "type[StateBase]" is not assignable to "type[JyKet]"
-       Type "type[StateBase]" is not assignable to type "type[JyKet]"
+         Type "type[StateBase]" is not assignable to type "type[JyKet]"
-       "type[StateBase]" is not assignable to "type[JzKet]"
+         "type[StateBase]" is not assignable to "type[JzKet]"
-       Type "type[StateBase]" is not assignable to type "type[JzKet]"
-       "type[StateBase]" is not assignable to "type[Ket]" (reportArgumentType)
+         Type "type[StateBase]" is not assignable to type "type[JzKet]" (reportArgumentType)
+   /tmp/mypy_primer/projects/sympy/sympy/polys/polyroots.py:1127:39 - error: Cannot access attribute "items" for class "type[type[Order]]"
+     Attribute "items" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/polys/polyroots.py:1143:26 - error: Argument of type "Any | type[None] | type[Unknown] | type[type[Unknown]] | dict[Unknown, Unknown]" cannot be assigned to parameter "iterable" of type "Iterable[list[bytes]]" in function "__init__"
+   /tmp/mypy_primer/projects/sympy/sympy/polys/polyroots.py:1143:26 - error: Argument of type "Any | type[None] | type[Unknown] | type[type[Unknown]] | type[type[Order]] | dict[Unknown, Unknown]" cannot be assigned to parameter "iterable" of type "Iterable[list[bytes]]" in function "__init__"
-     Type "Any | type[None] | type[Unknown] | type[type[Unknown]] | dict[Unknown, Unknown]" is not assignable to type "Iterable[list[bytes]]"
+     Type "Any | type[None] | type[Unknown] | type[type[Unknown]] | type[type[Order]] | dict[Unknown, Unknown]" is not assignable to type "Iterable[list[bytes]]"
+   /tmp/mypy_primer/projects/sympy/sympy/polys/polyroots.py:1145:28 - error: Expected no type arguments for class "Order" (reportInvalidTypeArguments)
-   /tmp/mypy_primer/projects/sympy/sympy/polys/polyroots.py:1148:26 - error: Argument of type "Any | type[None] | type[Unknown] | type[type[Unknown]] | dict[Unknown, Unknown]" cannot be assigned to parameter "iterable" of type "Iterable[list[bytes]]" in function "__init__"
+   /tmp/mypy_primer/projects/sympy/sympy/polys/polyroots.py:1148:26 - error: Argument of type "Any | type[None] | type[Unknown] | type[type[Unknown]] | type[type[Order]] | dict[Unknown, Unknown]" cannot be assigned to parameter "iterable" of type "Iterable[list[bytes]]" in function "__init__"
-     Type "Any | type[None] | type[Unknown] | type[type[Unknown]] | dict[Unknown, Unknown]" is not assignable to type "Iterable[list[bytes]]"
+     Type "Any | type[None] | type[Unknown] | type[type[Unknown]] | type[type[Order]] | dict[Unknown, Unknown]" is not assignable to type "Iterable[list[bytes]]"
+   /tmp/mypy_primer/projects/sympy/sympy/polys/polyroots.py:1150:28 - error: Expected no type arguments for class "Order" (reportInvalidTypeArguments)
+     Attribute "items" is unknown (reportAttributeAccessIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/polys/polyroots.py:1153:28 - error: Cannot access attribute "items" for class "type[type[Order]]"
+   /tmp/mypy_primer/projects/sympy/sympy/polys/polyroots.py:1158:28 - error: Cannot access attribute "items" for class "type[type[Order]]"
+     Attribute "items" is unknown (reportAttributeAccessIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/polys/polyroots.py:1163:12 - error: Cannot access attribute "update" for class "type[type[Order]]"
+     Attribute "update" is unknown (reportAttributeAccessIssue)
+     Attribute "values" is unknown (reportAttributeAccessIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/polys/polyroots.py:1165:30 - error: Cannot access attribute "values" for class "type[type[Order]]"
-   /tmp/mypy_primer/projects/sympy/sympy/polys/polyroots.py:1179:26 - error: Operator "*" not supported for types "list[Unknown]" and "Any | type[None] | Unknown | type[type[Unknown]]"
+   /tmp/mypy_primer/projects/sympy/sympy/polys/polyroots.py:1179:26 - error: Operator "*" not supported for types "list[Unknown]" and "Any | type[None] | Unknown | type[type[Unknown]] | type[type[Order]]"
+     Operator "*" not supported for types "list[Unknown]" and "type[type[Unknown]]" when expected type is "Iterable[Unknown]"
-     Operator "*" not supported for types "list[Unknown]" and "type[type[Unknown]]" when expected type is "Iterable[Unknown]" (reportOperatorIssue)
+     Operator "*" not supported for types "list[Unknown]" and "type[type[Order]]" when expected type is "Iterable[Unknown]" (reportOperatorIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/polys/polyroots.py:1179:40 - error: Expected no type arguments for class "Order" (reportInvalidTypeArguments)
-     Argument types: (Literal[80]) (reportCallIssue)
+     Argument types: (Unbound) (reportCallIssue)
-     Argument types: (Literal[80]) (reportCallIssue)
+     Argument types: (Unbound) (reportCallIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/polys/numberfields/tests/test_primes.py:36:14 - error: "type[type[type[int]]]" is not iterable
+     "__iter__" method not defined (reportGeneralTypeIssues)
+     "__iter__" method not defined (reportGeneralTypeIssues)
+   /tmp/mypy_primer/projects/sympy/sympy/polys/numberfields/tests/test_primes.py:58:14 - error: "type[type[type[int]]]" is not iterable
+   /tmp/mypy_primer/projects/sympy/sympy/polys/numberfields/tests/test_utilities.py:20:41 - error: Expected no type arguments for class "int" (reportInvalidTypeArguments)
+   /tmp/mypy_primer/projects/sympy/sympy/polys/numberfields/tests/test_utilities.py:24:26 - error: Expected no type arguments for class "int" (reportInvalidTypeArguments)
+   /tmp/mypy_primer/projects/sympy/sympy/polys/numberfields/tests/test_utilities.py:25:22 - error: Expected no type arguments for class "int" (reportInvalidTypeArguments)
+   /tmp/mypy_primer/projects/sympy/sympy/polys/numberfields/tests/test_utilities.py:25:40 - error: Expected no type arguments for class "int" (reportInvalidTypeArguments)
+   /tmp/mypy_primer/projects/sympy/sympy/polys/numberfields/tests/test_utilities.py:27:29 - error: Expected no type arguments for class "int" (reportInvalidTypeArguments)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/ode/hypergeometric.py:105:15 - error: Cannot access attribute "is_rational_function" for class "type[type[bool]]"
+     Attribute "is_rational_function" is unknown (reportAttributeAccessIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/ode/hypergeometric.py:105:15 - error: Cannot access attribute "is_rational_function" for class "type[type[Basic]]"
+     Attribute "is_rational_function" is unknown (reportAttributeAccessIssue)
+     Attribute "as_numer_denom" is unknown (reportAttributeAccessIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/ode/hypergeometric.py:108:19 - error: Cannot access attribute "as_numer_denom" for class "type[type[bool]]"
+     Attribute "as_numer_denom" is unknown (reportAttributeAccessIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/ode/hypergeometric.py:108:19 - error: Cannot access attribute "as_numer_denom" for class "type[type[Basic]]"
- 81652 errors, 1227 warnings, 0 informations 
+ 81671 errors, 1227 warnings, 0 informations 

bokeh (https://github.com/bokeh/bokeh)
-   /tmp/mypy_primer/projects/bokeh/src/bokeh/core/has_props.py:114:12 - error: Type "type[C@abstract]" is not assignable to return type "C@abstract"
-     Type "type[C@abstract]" is not assignable to type "C@abstract" (reportReturnType)
- 3548 errors, 294 warnings, 0 informations 
+ 3547 errors, 294 warnings, 0 informations 

xarray-dataclasses (https://github.com/astropenguin/xarray-dataclasses)
-   /tmp/mypy_primer/projects/xarray-dataclasses/xarray_dataclasses/datamodel.py:216:28 - error: Argument of type "type[<subclass of DataClass[PInit@eval_dataclass] and DataclassInstance>] | <subclass of type[DataClass[PInit@eval_dataclass]] and DataclassInstance> | <subclass of DataClass[PInit@eval_dataclass] and type[DataclassInstance]>" cannot be assigned to parameter "obj" of type "(...) -> Any" in function "get_type_hints"
-     Type "type[<subclass of DataClass[PInit@eval_dataclass] and DataclassInstance>] | <subclass of type[DataClass[PInit@eval_dataclass]] and DataclassInstance> | <subclass of DataClass[PInit@eval_dataclass] and type[DataclassInstance]>" is not assignable to type "(...) -> Any"
-       Type "<subclass of DataClass[PInit@eval_dataclass] and type[DataclassInstance]>" is not assignable to type "(...) -> Any" (reportArgumentType)
- 56 errors, 160 warnings, 0 informations 
+ 55 errors, 160 warnings, 0 informations 

comtypes (https://github.com/enthought/comtypes)
- /tmp/mypy_primer/projects/comtypes/comtypes/_meta.py
-   /tmp/mypy_primer/projects/comtypes/comtypes/_meta.py:92:29 - error: Class cannot derive from itself (reportGeneralTypeIssues)
+   /tmp/mypy_primer/projects/comtypes/comtypes/_post_coinit/unknwn.py:129:13 - error: Expected 0 positional arguments (reportCallIssue)
-   /tmp/mypy_primer/projects/comtypes/comtypes/_post_coinit/unknwn.py:405:24 - error: Class cannot derive from itself (reportGeneralTypeIssues)
+   /tmp/mypy_primer/projects/comtypes/comtypes/_post_coinit/unknwn.py:411:7 - error: The metaclass of a derived class must be a subclass of the metaclasses of all its base classes
+     Metaclass "_compointer_meta" conflicts with "_CDataMeta" (reportGeneralTypeIssues)
+   /tmp/mypy_primer/projects/comtypes/comtypes/_post_coinit/unknwn.py:426:22 - error: Cannot access attribute "Release" for class "_compointer_base*"
+     Attribute "Release" is unknown (reportAttributeAccessIssue)
+   /tmp/mypy_primer/projects/comtypes/comtypes/_post_coinit/unknwn.py:486:41 - error: Cannot access attribute "__com_interface__" for class "type[_compointer_base]*"
+     Attribute "__com_interface__" is unknown (reportAttributeAccessIssue)
- 539 errors, 28 warnings, 0 informations 
+ 541 errors, 28 warnings, 0 informations 

@erictraut erictraut closed this Oct 29, 2024
@erictraut erictraut deleted the issue-9217-2 branch October 29, 2024 23:32
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