Skip to content

Changed handling of Self within a protocol.#10212

Closed
erictraut wants to merge 2 commits into
mainfrom
TestProtocolSelf
Closed

Changed handling of Self within a protocol.#10212
erictraut wants to merge 2 commits into
mainfrom
TestProtocolSelf

Conversation

@erictraut
Copy link
Copy Markdown
Collaborator

DO NOT MERGE: THIS IS JUST A TEST

DO NOT MERGE: THIS IS JUST A TEST
@github-actions

This comment has been minimized.

* main:
  Fixed a bug that results in a false negative when a class that derives from `type[Any]` is assigned to any other type. This addresses #10185. (#10224)
  Removed support for `ru` and `ur` string prefixes. These were supported in Python 2.7 but are syntax errors in Python 3.x. This addresses #10222. (#10223)
  Fixed a bug that results in a false negative when the specialization of a TypeVarTuple includes multiple unpacked tuples of unknown length. This addresses #10219. (#10220)
  Extended `reportUnknownVariableType` check to include cases where a value whose type is a generic class parameterized by `Unknown` is assigned to a variable with a declared type. This addresses #10214. (#10217)
  Partly addressed inconsistency between override validation and protocol matching introduced in recent change. (#10215)
  Fix typo in docs (#10213)
@github-actions
Copy link
Copy Markdown
Contributor

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

sympy (https://github.com/sympy/sympy)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:554:13 - error: Cannot access attribute "canon_bp" for class "Expr"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:554:13 - error: Cannot access attribute "canon_bp" for class "One"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:554:13 - error: Cannot access attribute "canon_bp" for class "Zero"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:554:13 - error: Cannot access attribute "canon_bp" for class "TensExpr"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:558:15 - error: Cannot access attribute "canon_bp" for class "Expr"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:558:15 - error: Cannot access attribute "canon_bp" for class "Zero"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:558:15 - error: Cannot access attribute "canon_bp" for class "One"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:558:15 - error: Cannot access attribute "canon_bp" for class "NegativeOne"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:558:15 - error: Cannot access attribute "canon_bp" for class "Integer"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:558:15 - error: Cannot access attribute "canon_bp" for class "Rational"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:558:15 - error: Cannot access attribute "canon_bp" for class "NaN"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:558:15 - error: Cannot access attribute "canon_bp" for class "ComplexInfinity"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:558:15 - error: Cannot access attribute "canon_bp" for class "Half"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:558:15 - error: Cannot access attribute "canon_bp" for class "Infinity"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:558:15 - error: Cannot access attribute "canon_bp" for class "NegativeInfinity"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:558:15 - error: Cannot access attribute "canon_bp" for class "Float"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:558:15 - error: Cannot access attribute "canon_bp" for class "Number"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:577:13 - error: Cannot access attribute "canon_bp" for class "Expr"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:577:13 - error: Cannot access attribute "canon_bp" for class "One"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:577:13 - error: Cannot access attribute "canon_bp" for class "NegativeOne"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:577:13 - error: Cannot access attribute "canon_bp" for class "Zero"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:577:13 - error: Cannot access attribute "canon_bp" for class "Integer"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:577:13 - error: Cannot access attribute "canon_bp" for class "Rational"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:577:13 - error: Cannot access attribute "canon_bp" for class "NaN"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:577:13 - error: Cannot access attribute "canon_bp" for class "ComplexInfinity"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:577:13 - error: Cannot access attribute "canon_bp" for class "Half"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:577:13 - error: Cannot access attribute "canon_bp" for class "Infinity"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:577:13 - error: Cannot access attribute "canon_bp" for class "NegativeInfinity"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:577:13 - error: Cannot access attribute "canon_bp" for class "Float"
-     Attribute "canon_bp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:1602:36 - error: "__getitem__" method not defined on type "NegativeOne" (reportIndexIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:1602:36 - error: "__getitem__" method not defined on type "One" (reportIndexIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:1602:36 - error: "__getitem__" method not defined on type "TensExpr" (reportIndexIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:1608:43 - error: "__getitem__" method not defined on type "NegativeOne" (reportIndexIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:1608:43 - error: "__getitem__" method not defined on type "One" (reportIndexIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:1608:43 - error: "__getitem__" method not defined on type "TensExpr" (reportIndexIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:1663:41 - error: Operator "*" not supported for types "Literal[2]" and "Unknown | Any | Basic | ZeroArray | ArrayTensorProduct | ArrayContraction | Tuple | Indexed | ImmutableDenseNDimArray | NDimArray | None"
+   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:1663:41 - error: Operator "*" not supported for types "Literal[2]" and "Unknown | Any | Basic | Zero | ZeroArray | ArrayTensorProduct | ArrayContraction | Tuple | Indexed | ImmutableDenseNDimArray | NDimArray | None"
-     Attribute "data" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:1694:44 - error: Cannot access attribute "data" for class "NegativeOne"
-     Attribute "data" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:1694:44 - error: Cannot access attribute "data" for class "One"
-     Attribute "data" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:1694:44 - error: Cannot access attribute "data" for class "TensExpr"
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:1697:17 - error: Operator "-" not supported for type "Unknown | Any | Basic | ZeroArray | ArrayTensorProduct | ArrayContraction | Tuple | Indexed | ImmutableDenseNDimArray | NDimArray" (reportOperatorIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:1697:17 - error: Operator "-" not supported for type "Unknown | Any | Basic | Zero | ZeroArray | ArrayTensorProduct | ArrayContraction | Tuple | Indexed | ImmutableDenseNDimArray | NDimArray" (reportOperatorIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:2029:9 - error: Operator "+" not supported for types "Equality | Unknown | Relational | Unequality | Integer | NaN | Sum" and "Equality | Unknown | Relational | Unequality | Integer | NaN | Sum"
+   /tmp/mypy_primer/projects/sympy/sympy/tensor/tests/test_tensor.py:2029:9 - error: Operator "+" not supported for types "Equality | Unknown | NaN | Sum" and "Equality | Unknown | NaN | Sum"
-     Operator "+" not supported for types "Equality" and "Equality"
+     Operator "+" not supported for types "Equality" and "Equality" (reportOperatorIssue)
-     Operator "+" not supported for types "Equality" and "Relational"
-     Operator "+" not supported for types "Equality" and "Unequality"
-     Operator "+" not supported for types "Relational" and "Equality"
-     Operator "+" not supported for types "Relational" and "Relational"
-     Operator "+" not supported for types "Relational" and "Unequality"
-     Operator "+" not supported for types "Unequality" and "Equality"
-     Operator "+" not supported for types "Unequality" and "Relational"
-     ... (reportOperatorIssue)

... (truncated 103 lines) ...

psycopg (https://github.com/psycopg/psycopg)
-         Type "(*args: Any) -> NoReturn" is not assignable to type "(conninfo: bytes) -> FinishedPGconn"
+         Type "(*args: Any) -> NoReturn" is not assignable to type "(conninfo: bytes) -> PGconn"
-         Type "(*args: Any) -> NoReturn" is not assignable to type "(conninfo: bytes) -> FinishedPGconn"
+         Type "(*args: Any) -> NoReturn" is not assignable to type "(conninfo: bytes) -> PGconn"
-   /tmp/mypy_primer/projects/psycopg/psycopg/psycopg/pq/pq_ctypes.py:106:35 - error: Argument of type "Self@PGconn" cannot be assigned to parameter "pgconn" of type "PGconn" in function "connection_summary"
-     "PGconn*" is incompatible with protocol "PGconn"
-       "connect" is an incompatible type
-         Type "(conninfo: bytes) -> PGconn" is not assignable to type "(conninfo: bytes) -> Self@PGconn"
-           Function return type "PGconn" is incompatible with type "Self@PGconn"
-             Type "PGconn" is not assignable to type "Self@PGconn"
-       "connect_start" is an incompatible type
-         Type "(conninfo: bytes) -> PGconn" is not assignable to type "(conninfo: bytes) -> Self@PGconn"
-           Function return type "PGconn" is incompatible with type "Self@PGconn"
-     ... (reportArgumentType)
- 1759 errors, 113 warnings, 0 informations 
+ 1758 errors, 113 warnings, 0 informations 

prefect (https://github.com/PrefectHQ/prefect)
-           Type "type[NotSet]" is not assignable to type "NotSet"
+         Type "type[NotSet]" is not assignable to type "str"

pip (https://github.com/pypa/pip)
+           "name" is not present (reportArgumentType)
-           "name" is not present
-             "_WrappedBuffer" is not assignable to "BufferedRWPair" (reportArgumentType)
+           "name" is not present (reportArgumentType)
-           "name" is not present
-             "_WrappedBuffer" is not assignable to "BufferedRWPair" (reportArgumentType)

streamlit (https://github.com/streamlit/streamlit)
-       Type "type[EnumA]" is not assignable to type "EnumA"
-     ... (reportArgumentType)
+       "__dataframe__" is not present (reportArgumentType)

xarray (https://github.com/pydata/xarray)
-           "_overwrite_indexes" is not present
+           "_overwrite_indexes" is not present (reportArgumentType)
-             "Alignable" is not assignable to "Variable"
-             "Alignable" is not assignable to "Variable" (reportArgumentType)
-           "_overwrite_indexes" is not present
+           "_overwrite_indexes" is not present (reportArgumentType)
-             "Alignable" is not assignable to "Variable"
-             "Alignable" is not assignable to "Variable" (reportArgumentType)
-             "_array[_ShapeType_co@_arrayfunction, _DType_co@_arrayfunction]" is not assignable to "DataArray"
+             "_array[_ShapeType_co@_arrayfunction, _DType_co@_arrayfunction]" is incompatible with protocol "_arrayfunction[Unknown, Unknown]"

urllib3 (https://github.com/urllib3/urllib3)
+       "HTTPConnection" is incompatible with protocol "BaseHTTPSConnection"
-         "BaseHTTPConnection" is not assignable to "HTTPConnection"
+       Type "type[HTTPConnection]" is not assignable to type "type[BaseHTTPSConnection]"
-         "BaseHTTPConnection" is not assignable to "HTTPConnection"
-         "BaseHTTPConnection" is not assignable to "EmscriptenHTTPConnection"
-         "BaseHTTPConnection" is not assignable to "EmscriptenHTTPConnection"
+       "EmscriptenHTTPConnection" is incompatible with protocol "BaseHTTPSConnection"
+       Type "type[EmscriptenHTTPConnection]" is not assignable to type "type[BaseHTTPSConnection]"
-       "BaseHTTPConnection" is not assignable to "EmscriptenHTTPSConnection"
+       "BaseHTTPConnection" is incompatible with protocol "BaseHTTPSConnection"
-         Type "BaseHTTPConnection" is not assignable to type "Self@EmscriptenHTTPConnection"
-         Type "BaseHTTPConnection" is not assignable to type "Self@EmscriptenHTTPConnection"
-         Type "BaseHTTPConnection" is not assignable to type "Self@EmscriptenHTTPConnection"
+       "EmscriptenHTTPConnection*" is incompatible with protocol "BaseHTTPSConnection"
+         "cert_reqs" is not present
+         "assert_hostname" is not present
-             Type "int | None" is not assignable to type "int"
+             Type "int | None" is not assignable to type "int" (reportAssignmentType)
-       "BaseHTTPConnection" is not assignable to "EmscriptenHTTPConnection"
-       "BaseHTTPConnection" is not assignable to "EmscriptenHTTPConnection"
-       "BaseHTTPConnection" is not assignable to "EmscriptenHTTPConnection" (reportAssignmentType)
-       "BaseHTTPConnection" is not assignable to "EmscriptenHTTPSConnection"
+       "BaseHTTPConnection" is incompatible with protocol "BaseHTTPSConnection"
-       "BaseHTTPConnection" is not assignable to "EmscriptenHTTPSConnection"
+       "BaseHTTPConnection" is incompatible with protocol "BaseHTTPSConnection"
+       "HTTPConnection" is not assignable to "None" (reportArgumentType)
-         "BaseHTTPConnection" is not assignable to "HTTPConnection"
-         "BaseHTTPConnection" is not assignable to "HTTPConnection"
-         "BaseHTTPConnection" is not assignable to "HTTPConnection"
-     ... (reportArgumentType)

nionutils (https://github.com/nion-software/nionutils)
-       "ModelLike" is not assignable to "RecordModel"
-       "ModelLike" is not assignable to "ArrayModel"

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
+   /tmp/mypy_primer/projects/hydra-zen/tests/annotations/declarations.py:461:9 - error: Type "partial[int]" is not assignable to declared type "Partial[int]"
+     "partial[int]" is incompatible with protocol "Partial[int]"
+       "__new__" is an incompatible type
+         Type "(cls: type[partial[int]], func: (...) -> int, /, ...) -> partial[int]" is not assignable to type "(cls: type[Partial[int]], __func: (...) -> T2@Partial, ...) -> Partial[int]"
+           Parameter 1: type "type[Partial[int]]" is incompatible with type "type[partial[int]]"
+             "type[Partial[int]]" is not assignable to "type[partial[int]]"
+             Type "type[Partial[int]]" is not assignable to type "type[partial[int]]" (reportAssignmentType)
+   /tmp/mypy_primer/projects/hydra-zen/tests/annotations/declarations.py:471:23 - error: Type "partial[int]" is not assignable to declared type "Partial[int]"
+     "partial[int]" is incompatible with protocol "Partial[int]"
+       "__new__" is an incompatible type
+         Type "(cls: type[partial[int]], func: (...) -> int, /, ...) -> partial[int]" is not assignable to type "(cls: type[Partial[int]], __func: (...) -> T2@Partial, ...) -> Partial[int]"
+           Parameter 1: type "type[Partial[int]]" is incompatible with type "type[partial[int]]"
+             "type[Partial[int]]" is not assignable to "type[partial[int]]"
+             Type "type[Partial[int]]" is not assignable to type "type[partial[int]]" (reportAssignmentType)
+   /tmp/mypy_primer/projects/hydra-zen/tests/annotations/declarations.py:472:24 - error: Type "partial[bool]" is not assignable to declared type "Partial[bool]"
+     "partial[bool]" is incompatible with protocol "Partial[bool]"
+       "__new__" is an incompatible type
+         Type "(cls: type[partial[bool]], func: (...) -> bool, /, ...) -> partial[bool]" is not assignable to type "(cls: type[Partial[bool]], __func: (...) -> T2@Partial, ...) -> Partial[bool]"
+           Parameter 1: type "type[Partial[bool]]" is incompatible with type "type[partial[bool]]"
+             "type[Partial[bool]]" is not assignable to "type[partial[bool]]"
+             Type "type[Partial[bool]]" is not assignable to type "type[partial[bool]]" (reportAssignmentType)
- 183 errors, 13 warnings, 183 informations 
+ 186 errors, 13 warnings, 183 informations 

spack (https://github.com/spack/spack)
-     Type "type[list[Unknown]]" is not assignable to type "list[Unknown]"
-     Type "type[list[Unknown]]" is not assignable to type "list[Unknown]"
-     Type "type[list[Unknown]]" is not assignable to type "list[Unknown]"

@erictraut erictraut closed this Apr 7, 2025
@erictraut erictraut deleted the TestProtocolSelf branch April 7, 2025 20:44
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