Skip to content

Commit 022d9bc

Browse files
committed
Revert "TypeForm: Enable by default (#21262)"
This reverts commit dd851f5.
1 parent 8826288 commit 022d9bc

6 files changed

Lines changed: 78 additions & 11 deletions

File tree

docs/source/command_line.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ format into the specified directory.
12111211
Enabling incomplete/experimental features
12121212
*****************************************
12131213

1214-
.. option:: --enable-incomplete-feature {PreciseTupleTypes,InlineTypedDict}
1214+
.. option:: --enable-incomplete-feature {PreciseTupleTypes,InlineTypedDict,TypeForm}
12151215

12161216
Some features may require several mypy releases to implement, for example
12171217
due to their complexity, potential for backwards incompatibility, or
@@ -1266,6 +1266,8 @@ List of currently incomplete/experimental features:
12661266
def test_values() -> {"width": int, "description": str}:
12671267
return {"width": 42, "description": "test"}
12681268
1269+
* ``TypeForm``: this feature enables ``TypeForm``, as described in
1270+
`PEP 747 – Annotating Type Forms <https://peps.python.org/pep-0747/>_`.
12691271

12701272

12711273
Miscellaneous

mypy/options.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ class BuildType:
9494
NEW_GENERIC_SYNTAX: Final = "NewGenericSyntax"
9595
INLINE_TYPEDDICT: Final = "InlineTypedDict"
9696
TYPE_FORM: Final = "TypeForm"
97-
INCOMPLETE_FEATURES: Final = frozenset((PRECISE_TUPLE_TYPES, INLINE_TYPEDDICT))
98-
COMPLETE_FEATURES: Final = frozenset((TYPE_VAR_TUPLE, UNPACK, NEW_GENERIC_SYNTAX, TYPE_FORM))
97+
INCOMPLETE_FEATURES: Final = frozenset((PRECISE_TUPLE_TYPES, INLINE_TYPEDDICT, TYPE_FORM))
98+
COMPLETE_FEATURES: Final = frozenset((TYPE_VAR_TUPLE, UNPACK, NEW_GENERIC_SYNTAX))
9999

100100

101101
class Options:

mypy/semanal.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
type_aliases_source_versions,
196196
typing_extensions_aliases,
197197
)
198-
from mypy.options import Options
198+
from mypy.options import TYPE_FORM, Options
199199
from mypy.patterns import (
200200
AsPattern,
201201
ClassPattern,
@@ -3701,7 +3701,8 @@ def analyze_lvalues(self, s: AssignmentStmt) -> None:
37013701
)
37023702

37033703
def analyze_rvalue_as_type_form(self, s: AssignmentStmt) -> None:
3704-
self.try_parse_as_type_expression(s.rvalue)
3704+
if TYPE_FORM in self.options.enable_incomplete_feature:
3705+
self.try_parse_as_type_expression(s.rvalue)
37053706

37063707
def apply_dynamic_class_hook(self, s: AssignmentStmt) -> None:
37073708
if not isinstance(s.rvalue, CallExpr):
@@ -5451,7 +5452,8 @@ def visit_return_stmt(self, s: ReturnStmt) -> None:
54515452
self.fail('"return" not allowed in except* block', s, serious=True)
54525453
if s.expr:
54535454
s.expr.accept(self)
5454-
self.try_parse_as_type_expression(s.expr)
5455+
if TYPE_FORM in self.options.enable_incomplete_feature:
5456+
self.try_parse_as_type_expression(s.expr)
54555457
self.statement = old
54565458

54575459
def visit_raise_stmt(self, s: RaiseStmt) -> None:
@@ -6054,9 +6056,11 @@ def visit_call_expr(self, expr: CallExpr) -> None:
60546056
expr.analyzed.accept(self)
60556057
else:
60566058
# Normal call expression.
6059+
calculate_type_forms = TYPE_FORM in self.options.enable_incomplete_feature
60576060
for a in expr.args:
60586061
a.accept(self)
6059-
self.try_parse_as_type_expression(a)
6062+
if calculate_type_forms:
6063+
self.try_parse_as_type_expression(a)
60606064

60616065
if (
60626066
isinstance(expr.callee, MemberExpr)

mypy/typeanal.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
check_arg_kinds,
5050
check_param_names,
5151
)
52-
from mypy.options import INLINE_TYPEDDICT, Options
52+
from mypy.options import INLINE_TYPEDDICT, TYPE_FORM, Options
5353
from mypy.plugin import AnalyzeTypeContext, Plugin, TypeAnalyzerPluginInterface
5454
from mypy.semanal_shared import (
5555
SemanticAnalyzerCoreInterface,
@@ -674,6 +674,12 @@ def try_analyze_special_unbound_type(self, t: UnboundType, fullname: str) -> Typ
674674
item = AnyType(TypeOfAny.from_error)
675675
return TypeType.make_normalized(item, line=t.line, column=t.column)
676676
elif fullname in ("typing_extensions.TypeForm", "typing.TypeForm"):
677+
if TYPE_FORM not in self.options.enable_incomplete_feature:
678+
self.fail(
679+
"TypeForm is experimental,"
680+
" must be enabled with --enable-incomplete-feature=TypeForm",
681+
t,
682+
)
677683
if len(t.args) == 0:
678684
any_type = self.get_omitted_any(t)
679685
return TypeType(any_type, line=t.line, column=t.column, is_type_form=True)

test-data/unit/check-fastparse.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def call() -> str: pass
337337
[builtins fixtures/module.pyi]
338338

339339
[case testInvalidEscapeSequenceWarningsSuppressed]
340-
# flags: --python-version 3.15
340+
# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
341341
# Test that SyntaxWarnings for invalid escape sequences are suppressed
342342
# when parsing potential type expressions containing regex patterns or
343343
# similar strings. Callable arguments are always potential type expressions.

0 commit comments

Comments
 (0)