Skip to content

Commit ec7ce6b

Browse files
committed
add __type_checking__ keyword
1 parent 557d2d2 commit ec7ce6b

File tree

4 files changed

+280
-193
lines changed

4 files changed

+280
-193
lines changed

Doc/reference/lexical_analysis.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ exactly as written here:
348348
as def from nonlocal while
349349
assert del global not with
350350
async elif if or yield
351+
__type_checking__
351352

352353

353354
.. _soft-keywords:

Grammar/python.gram

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ atom[expr_ty]:
848848
| NAME
849849
| 'True' { _PyAST_Constant(Py_True, NULL, EXTRA) }
850850
| 'False' { _PyAST_Constant(Py_False, NULL, EXTRA) }
851+
| '__type_checking__' { _PyAST_Constant(Py_False, NULL, EXTRA) }
851852
| 'None' { _PyAST_Constant(Py_None, NULL, EXTRA) }
852853
| &(STRING|FSTRING_START) strings
853854
| NUMBER
@@ -1154,7 +1155,7 @@ invalid_arguments:
11541155
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, _PyPegen_get_last_comprehension_item(PyPegen_last_item(b, comprehension_ty)), "Generator expression must be parenthesized") }
11551156
| a=args ',' args { _PyPegen_arguments_parsing_error(p, a) }
11561157
invalid_kwarg:
1157-
| a[Token*]=('True'|'False'|'None') b='=' {
1158+
| a[Token*]=('True'|'False'|'None'|'__type_checking__') b='=' {
11581159
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "cannot assign to %s", PyBytes_AS_STRING(a->bytes)) }
11591160
| a=NAME b='=' expression for_if_clauses {
11601161
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '==' or ':=' instead of '='?")}
@@ -1209,7 +1210,7 @@ invalid_named_expression(memo):
12091210
a, "cannot use assignment expressions with %s", _PyPegen_get_expr_name(a)) }
12101211
| a=NAME '=' b=bitwise_or !('='|':=') {
12111212
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '==' or ':=' instead of '='?") }
1212-
| !(list|tuple|genexp|'True'|'None'|'False') a=bitwise_or b='=' bitwise_or !('='|':=') {
1213+
| !(list|tuple|genexp|'True'|'None'|'False'|'__type_checking__') a=bitwise_or b='=' bitwise_or !('='|':=') {
12131214
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot assign to %s here. Maybe you meant '==' instead of '='?",
12141215
_PyPegen_get_expr_name(a)) }
12151216

Lib/keyword.py

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)