Skip to content

Made PEP 747 (Annotating Type Forms) no longer experimental#11302

Open
Viicos wants to merge 1 commit intomicrosoft:mainfrom
Viicos:pep-747-no-exp
Open

Made PEP 747 (Annotating Type Forms) no longer experimental#11302
Viicos wants to merge 1 commit intomicrosoft:mainfrom
Viicos:pep-747-no-exp

Conversation

@Viicos
Copy link
Contributor

@Viicos Viicos commented Mar 2, 2026

as it was recently accepted: https://discuss.python.org/t/55984/103.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

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

bidict (https://github.com/jab/bidict)
+   .../projects/bidict/bidict/_typing.py:31:28 - error: Variable not allowed in type expression (reportInvalidTypeForm)
+   .../projects/bidict/bidict/_typing.py:31:28 - error: Type arguments for "Literal" must be None, a literal value (int, bool, str, or bytes), or an enum value (reportInvalidTypeForm)
- 12 errors, 2 warnings, 0 informations
+ 14 errors, 2 warnings, 0 informations

ibis (https://github.com/ibis-project/ibis)
+   .../projects/ibis/ibis/expr/datatypes/core.py:1062:23 - error: No parameter named "geotype" (reportCallIssue)
+   .../projects/ibis/ibis/expr/datatypes/core.py:1063:24 - error: No parameter named "geotype" (reportCallIssue)
- 7557 errors, 262 warnings, 0 informations
+ 7559 errors, 262 warnings, 0 informations

sympy (https://github.com/sympy/sympy)
+   .../projects/sympy/sympy/core/add.py:93:7 - error: Base classes for class "Add" define method "sort_key" in incompatible way
+     Return type mismatch: base method returns type "tuple[tuple[int, int, str], tuple[int, tuple[Unknown, ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One]", override returns type "tuple[tuple[int, int, str], tuple[int, tuple[tuple[tuple[int, int, str], tuple[int, tuple[Unknown, ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One] | Unknown | tuple[tuple[int, int, str | Unknown], tuple[int, tuple[Unknown, ...]] | tuple[int, tuple[str]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One], ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One] | Unknown, Number]"
+       "tuple[tuple[int, int, str], tuple[int, tuple[tuple[tuple[int, int, str], tuple[int, tuple[Unknown, ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One] | Unknown | tuple[tuple[int, int, str | Unknown], tuple[int, tuple[Unknown, ...]] | tuple[int, tuple[str]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One], ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One] | Unknown, Number]" is not assignable to "tuple[tuple[int, int, str], tuple[int, tuple[Unknown, ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One]"
+         Tuple entry 4 is incorrect type
+           "Number" is not assignable to "One" (reportIncompatibleMethodOverride)
-   .../projects/sympy/sympy/core/cache.py:135:8 - error: "lower" is not a known attribute of "None" (reportOptionalMemberAccess)
-   .../projects/sympy/sympy/core/cache.py:139:32 - error: Argument of type "str | Unknown | None" cannot be assigned to parameter "x" of type "ConvertibleToInt" in function "__new__"
-     Type "str | Unknown | None" is not assignable to type "ConvertibleToInt"
-       Type "None" is not assignable to type "ConvertibleToInt"
-         "None" is not assignable to "str"
-         "None" is incompatible with protocol "Buffer"
-           "__buffer__" is not present
-         "None" is incompatible with protocol "SupportsInt"
-           "__int__" is not present
-         "None" is incompatible with protocol "SupportsIndex"
-     ... (reportArgumentType)
-   .../projects/sympy/sympy/core/cache.py:139:32 - error: Argument of type "str | Unknown | None" cannot be assigned to parameter "x" of type "ConvertibleToInt" in function "__new__"
-     Type "str | Unknown | None" is not assignable to type "ConvertibleToInt"
-       Type "None" is not assignable to type "ConvertibleToInt"
-         "None" is not assignable to "str"
-         "None" is incompatible with protocol "Buffer"
-           "__buffer__" is not present
-         "None" is incompatible with protocol "SupportsInt"
-           "__int__" is not present
-         "None" is incompatible with protocol "SupportsIndex" (reportArgumentType)
+   .../projects/sympy/sympy/core/expr.py:167:9 - error: Method "sort_key" overrides class "Basic" in an incompatible manner
+     Return type mismatch: base method returns type "tuple[tuple[int, int, str], tuple[int, tuple[Unknown, ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One]", override returns type "tuple[tuple[int, int, str], tuple[int, tuple[tuple[tuple[int, int, str], tuple[int, tuple[Unknown, ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One] | Unknown | tuple[tuple[int, int, str | Unknown], tuple[int, tuple[Unknown, ...]] | tuple[int, tuple[str]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One], ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One] | Unknown, Number]"
+       "tuple[tuple[int, int, str], tuple[int, tuple[tuple[tuple[int, int, str], tuple[int, tuple[Unknown, ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One] | Unknown | tuple[tuple[int, int, str | Unknown], tuple[int, tuple[Unknown, ...]] | tuple[int, tuple[str]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One], ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One] | Unknown, Number]" is not assignable to "tuple[tuple[int, int, str], tuple[int, tuple[Unknown, ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One]"
+         Tuple entry 4 is incorrect type
+           "Number" is not assignable to "One" (reportIncompatibleMethodOverride)
+   .../projects/sympy/sympy/core/mul.py:95:7 - error: Base classes for class "Mul" define method "sort_key" in incompatible way
+     Return type mismatch: base method returns type "tuple[tuple[int, int, str], tuple[int, tuple[Unknown, ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One]", override returns type "tuple[tuple[int, int, str], tuple[int, tuple[tuple[tuple[int, int, str], tuple[int, tuple[Unknown, ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One] | Unknown | tuple[tuple[int, int, str | Unknown], tuple[int, tuple[Unknown, ...]] | tuple[int, tuple[str]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One], ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One] | Unknown, Number]"
+       "tuple[tuple[int, int, str], tuple[int, tuple[tuple[tuple[int, int, str], tuple[int, tuple[Unknown, ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One] | Unknown | tuple[tuple[int, int, str | Unknown], tuple[int, tuple[Unknown, ...]] | tuple[int, tuple[str]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One], ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One] | Unknown, Number]" is not assignable to "tuple[tuple[int, int, str], tuple[int, tuple[Unknown, ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One]"
+         Tuple entry 4 is incorrect type
+           "Number" is not assignable to "One" (reportIncompatibleMethodOverride)
- .../projects/sympy/sympy/discrete/convolutions.py
-   .../projects/sympy/sympy/discrete/convolutions.py:368:13 - error: No overloads for "__setitem__" match the provided arguments (reportCallIssue)
-   .../projects/sympy/sympy/discrete/convolutions.py:368:13 - error: Argument of type "Any | One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Expr" cannot be assigned to parameter "value" of type "Zero" in function "__setitem__"
-     Type "Any | One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Expr" is not assignable to type "Zero"
-       "Expr" is not assignable to "Zero" (reportArgumentType)
-   .../projects/sympy/sympy/discrete/convolutions.py:371:9 - error: No overloads for "__setitem__" match the provided arguments (reportCallIssue)
-   .../projects/sympy/sympy/discrete/convolutions.py:371:9 - error: Argument of type "Any | One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Expr" cannot be assigned to parameter "value" of type "Zero" in function "__setitem__"
-     Type "Any | One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Expr" is not assignable to type "Zero"
-       "Expr" is not assignable to "Zero" (reportArgumentType)
+   .../projects/sympy/sympy/functions/elementary/miscellaneous.py:380:7 - error: Base classes for class "MinMaxBase" define method "sort_key" in incompatible way
+     Return type mismatch: base method returns type "tuple[tuple[int, int, str], tuple[int, tuple[Unknown, ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One]", override returns type "tuple[tuple[int, int, str], tuple[int, tuple[tuple[tuple[int, int, str], tuple[int, tuple[Unknown, ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One] | Unknown | tuple[tuple[int, int, str | Unknown], tuple[int, tuple[Unknown, ...]] | tuple[int, tuple[str]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One], ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One] | Unknown, Number]"
+       "tuple[tuple[int, int, str], tuple[int, tuple[tuple[tuple[int, int, str], tuple[int, tuple[Unknown, ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One] | Unknown | tuple[tuple[int, int, str | Unknown], tuple[int, tuple[Unknown, ...]] | tuple[int, tuple[str]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One], ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One] | Unknown, Number]" is not assignable to "tuple[tuple[int, int, str], tuple[int, tuple[Unknown, ...]], tuple[tuple[Literal[1], Literal[0], Literal['Number']], tuple[int, tuple[()]], tuple[()], One], One]"
+         Tuple entry 4 is incorrect type

... (truncated 417 lines) ...

prefect (https://github.com/PrefectHQ/prefect)
-   .../projects/prefect/src/integrations/prefect-dask/tests/test_task_runners.py:104:31 - error: Argument of type "PrefectFuture[str]" cannot be assigned to parameter "b" of type "str" in function "submit"
-     "PrefectFuture[str]" is not assignable to "str" (reportArgumentType)
+   .../projects/prefect/src/integrations/prefect-dask/tests/test_task_runners.py:103:24 - error: Cannot access attribute "submit" for class "FunctionType"
+     Attribute "submit" is unknown (reportFunctionMemberAccess)
+   .../projects/prefect/src/integrations/prefect-dask/tests/test_task_runners.py:104:17 - error: Type of "task_c" could not be determined because it refers to itself (reportGeneralTypeIssues)
-     "str" is incompatible with protocol "Awaitable[_T_co@Awaitable]"
-       "__await__" is not present (reportGeneralTypeIssues)
-   .../projects/prefect/src/integrations/prefect-dask/tests/test_task_runners.py:110:22 - error: "str" is not awaitable
+   .../projects/prefect/src/integrations/prefect-dask/tests/test_task_runners.py:177:24 - error: Cannot access attribute "submit" for class "FunctionType"
+     Attribute "submit" is unknown (reportFunctionMemberAccess)
+   .../projects/prefect/src/integrations/prefect-dask/tests/test_task_runners.py:178:17 - error: Type of "task_c" could not be determined because it refers to itself (reportGeneralTypeIssues)
+   .../projects/prefect/src/integrations/prefect-dask/tests/test_task_runners.py:181:25 - error: Type of "test_flow" could not be determined because it refers to itself (reportGeneralTypeIssues)
+   .../projects/prefect/src/integrations/prefect-ray/tests/test_task_runners.py:220:24 - error: Cannot access attribute "submit" for class "FunctionType"
+     Attribute "submit" is unknown (reportFunctionMemberAccess)
+   .../projects/prefect/src/integrations/prefect-ray/tests/test_task_runners.py:221:17 - error: Type of "task_c" could not be determined because it refers to itself (reportGeneralTypeIssues)
+   .../projects/prefect/src/integrations/prefect-ray/tests/test_task_runners.py:224:19 - error: Type of "test_flow" could not be determined because it refers to itself (reportGeneralTypeIssues)
+   .../projects/prefect/src/integrations/prefect-ray/tests/test_task_runners.py:248:17 - error: Type of "task_c" could not be determined because it refers to itself (reportGeneralTypeIssues)
+   .../projects/prefect/src/integrations/prefect-ray/tests/test_task_runners.py:252:17 - error: Type of "test_flow" could not be determined because it refers to itself (reportGeneralTypeIssues)
-   .../projects/prefect/src/integrations/prefect-ray/tests/test_task_runners.py:226:22 - error: "str" is not awaitable
-     "str" is incompatible with protocol "Awaitable[_T_co@Awaitable]"
-       "__await__" is not present (reportGeneralTypeIssues)
-   .../projects/prefect/src/integrations/prefect-ray/tests/test_task_runners.py:255:24 - error: "tuple[PrefectFuture[NoReturn], PrefectFuture[NoReturn], PrefectFuture[Unknown], PrefectFuture[Unknown]]" is not awaitable
+   .../projects/prefect/src/integrations/prefect-ray/tests/test_task_runners.py:255:24 - error: "tuple[PrefectFuture[NoReturn], PrefectFuture[NoReturn], PrefectFuture[Unknown], Unknown]" is not awaitable
-     "tuple[PrefectFuture[NoReturn], PrefectFuture[NoReturn], PrefectFuture[Unknown], PrefectFuture[Unknown]]" is incompatible with protocol "Awaitable[_T_co@Awaitable]"
+     "tuple[PrefectFuture[NoReturn], PrefectFuture[NoReturn], PrefectFuture[Unknown], Unknown]" is incompatible with protocol "Awaitable[_T_co@Awaitable]"
+   .../projects/prefect/src/integrations/prefect-ray/tests/test_task_runners.py:294:24 - error: Cannot access attribute "submit" for class "FunctionType"
+     Attribute "submit" is unknown (reportFunctionMemberAccess)
+   .../projects/prefect/src/integrations/prefect-ray/tests/test_task_runners.py:295:17 - error: Type of "task_c" could not be determined because it refers to itself (reportGeneralTypeIssues)
+   .../projects/prefect/src/integrations/prefect-ray/tests/test_task_runners.py:298:25 - error: Type of "test_flow" could not be determined because it refers to itself (reportGeneralTypeIssues)
- 5978 errors, 179 warnings, 0 informations
+ 5988 errors, 179 warnings, 0 informations

pip (https://github.com/pypa/pip)
+ .../projects/pip/src/pip/_vendor/rich/table.py
+   .../projects/pip/src/pip/_vendor/rich/table.py:939:13 - error: No parameter named "caption_justify" (reportCallIssue)
- 1107 errors, 31 warnings, 0 informations
+ 1108 errors, 31 warnings, 0 informations

static-frame (https://github.com/static-frame/static-frame)
+   .../projects/static-frame/static_frame/core/util.py:1044:32 - error: Attribute type cannot use type variable "TVFGItem@__init__" scoped to local method (reportGeneralTypeIssues)
- 58 errors, 71 warnings, 0 informations
+ 59 errors, 71 warnings, 0 informations

rich (https://github.com/Textualize/rich)
+ .../projects/rich/rich/table.py
+   .../projects/rich/rich/table.py:948:13 - error: No parameter named "caption_justify" (reportCallIssue)
- 369 errors, 43 warnings, 0 informations
+ 370 errors, 43 warnings, 0 informations

@rchiodo
Copy link
Collaborator

rchiodo commented Mar 2, 2026

@Viicos, it looks like the changes are causing a single test failure.

@Viicos
Copy link
Contributor Author

Viicos commented Mar 2, 2026

Looks like a bug, that can be reproduce with the following MRE:

from typing import NamedTuple

# X is necessary to reproduce. Doesn't reproduce with only "a" as a field
X = NamedTuple("X", [("a", int), ("b", str)])
X(1, "1")


class Z(NamedTuple):
    c: list[str]
    d: list[int]


q6 = Z(["1"], [3])  # Error: Class definition for "Z" depends on itself

# This is necessary to reproduce
for a, b in zip(*q6):  # needs to be named a and b to reproduce
    pass
LLM analysis

The isTypeFormSupported guard on getTypeOfStringList (line 1715) was the critical one. By removing it, the commit causes every string literal to be
speculatively evaluated as a type expression to extract TypeForm info.

The chain of events:

  1. X = NamedTuple("X", [("a", int), ("b", str)]) is being processed
  2. The string "a" is now speculatively parsed as a type expression (line 1739: getTypeOfStringListAsType)
  3. "a" is parsed as the identifier a, which resolves to the for-loop variable a from for a, b in zip(*q6):
  4. To infer a's type, pyright evaluates the for-loop expression zip(*q6) 5. This requires q6's type → code flow follows to q6 = Z(["1"], [3]) 6. Evaluating Z(["1"], [3]) triggers Z's class evaluation → Z is marked PartiallyEvaluated
  5. validateConstructorArgs calls validateMetaclassCall first (constructors.ts:132), which calls getBoundCallMethod → getTypeOfBoundMember(Z,
    "call")
  6. Z is still PartiallyEvaluated → cycle error

The reason both X and the zip call are needed:

  • X is needed because its "a" string literal is what triggers the speculative type evaluation
  • *zip(q6) is needed because the for-loop variable a is what the identifier a resolves to, and evaluating that loop requires Z's constructor

The fix should restore the isTypeFormSupported guard specifically for the string-as-TypeForm path, or find a way to avoid the speculative type
evaluation causing this cascade.

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.

2 participants