Skip to content

Commit 565f103

Browse files
committed
gh-159672: Remove obsolete keyword typo support
1 parent 30d8199 commit 565f103

6 files changed

Lines changed: 15 additions & 55 deletions

File tree

‎Grammar/python.gram‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,11 @@ func_type[mod_ty]: '(' a=[type_expressions] ')' '->' b=expression NEWLINE* ENDMA
9797
statements[asdl_stmt_seq*]: a=statement+ { (asdl_stmt_seq*)_PyPegen_seq_flatten(p, a) }
9898

9999
statement[asdl_stmt_seq*]:
100-
| a=compound_stmt { _PyPegen_register_stmts(p ,
101-
(asdl_stmt_seq*)_PyPegen_singleton_seq(p, a)
102-
) }
100+
| a=compound_stmt { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a) }
103101
| a[asdl_stmt_seq*]=simple_stmts { a }
104102

105103
single_compound_stmt[asdl_stmt_seq*]:
106-
| a=compound_stmt {
107-
_PyPegen_register_stmts(p, (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a)) }
104+
| a=compound_stmt { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a) }
108105

109106
statement_newline[asdl_stmt_seq*]:
110107
| a=single_compound_stmt NEWLINE { a }

‎Lib/codeop.py‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
PyCF_ONLY_AST = 0x400
4848
PyCF_ALLOW_INCOMPLETE_INPUT = 0x4000
4949

50-
def _maybe_compile(compiler, source, filename, symbol, flags):
50+
def _maybe_compile(compiler, source, filename, symbol):
5151
# Check for source consisting of only blank lines and comments.
5252
for line in source.split("\n"):
5353
line = line.strip()
@@ -61,21 +61,22 @@ def _maybe_compile(compiler, source, filename, symbol, flags):
6161
with warnings.catch_warnings():
6262
warnings.simplefilter("ignore", (SyntaxWarning, DeprecationWarning))
6363
try:
64-
compiler(source, filename, symbol, flags=flags)
64+
compiler(source, filename, symbol)
6565
except _IncompleteInputError:
6666
return None
6767
except SyntaxError: # Let other compile() errors propagate.
6868
pass
6969

7070
return compiler(source, filename, symbol, incomplete_input=False)
7171

72-
def _compile(source, filename, symbol, incomplete_input=True, *, flags=0):
72+
def _compile(source, filename, symbol, incomplete_input=True):
73+
flags = 0
7374
if incomplete_input:
7475
flags |= PyCF_ALLOW_INCOMPLETE_INPUT
7576
flags |= PyCF_DONT_IMPLY_DEDENT
7677
return compile(source, filename, symbol, flags)
7778

78-
def compile_command(source, filename="<input>", symbol="single", flags=0):
79+
def compile_command(source, filename="<input>", symbol="single"):
7980
r"""Compile a command and determine whether it is incomplete.
8081
8182
Arguments:
@@ -94,7 +95,7 @@ def compile_command(source, filename="<input>", symbol="single", flags=0):
9495
syntax error (OverflowError and ValueError can be produced by
9596
malformed literals).
9697
"""
97-
return _maybe_compile(_compile, source, filename, symbol, flags)
98+
return _maybe_compile(_compile, source, filename, symbol)
9899

99100
class Compile:
100101
"""Instances of this class behave much like the built-in compile
@@ -146,4 +147,4 @@ def __call__(self, source, filename="<input>", symbol="single"):
146147
syntax error (OverflowError and ValueError can be produced by
147148
malformed literals).
148149
"""
149-
return _maybe_compile(self.compiler, source, filename, symbol, flags=self.compiler.flags)
150+
return _maybe_compile(self.compiler, source, filename, symbol)

‎Parser/action_helpers.c‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,23 +2152,3 @@ _PyPegen_checked_from_import(Parser *p, asdl_seq *dots, expr_ty module_name,
21522152
return _PyAST_ImportFrom(module, names, level, lazy_token ? 1 : 0, lineno,
21532153
col_offset, end_lineno, end_col_offset, arena);
21542154
}
2155-
2156-
asdl_stmt_seq*
2157-
_PyPegen_register_stmts(Parser *p, asdl_stmt_seq* stmts) {
2158-
if (!p->call_invalid_rules) {
2159-
return stmts;
2160-
}
2161-
Py_ssize_t len = asdl_seq_LEN(stmts);
2162-
if (len == 0) {
2163-
return stmts;
2164-
}
2165-
stmt_ty last_stmt = asdl_seq_GET(stmts, len - 1);
2166-
if (p->last_stmt_location.lineno > last_stmt->lineno) {
2167-
return stmts;
2168-
}
2169-
p->last_stmt_location.lineno = last_stmt->lineno;
2170-
p->last_stmt_location.col_offset = last_stmt->col_offset;
2171-
p->last_stmt_location.end_lineno = last_stmt->end_lineno;
2172-
p->last_stmt_location.end_col_offset = last_stmt->end_col_offset;
2173-
return stmts;
2174-
}

‎Parser/parser.c‎

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

‎Parser/pegen.c‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ compute_parser_flags(PyCompilerFlags *flags)
968968

969969
Parser *
970970
_PyPegen_Parser_New(struct tok_state *tok, int start_rule, int flags,
971-
int feature_version, int *errcode, const char* source, PyArena *arena)
971+
int feature_version, int *errcode, PyArena *arena)
972972
{
973973
Parser *p = PyMem_Malloc(sizeof(Parser));
974974
if (p == NULL) {
@@ -1023,10 +1023,6 @@ _PyPegen_Parser_New(struct tok_state *tok, int start_rule, int flags,
10231023
p->level = 0;
10241024
p->call_invalid_rules = 0;
10251025
p->input_exhausted = 0;
1026-
p->last_stmt_location.lineno = 0;
1027-
p->last_stmt_location.col_offset = 0;
1028-
p->last_stmt_location.end_lineno = 0;
1029-
p->last_stmt_location.end_col_offset = 0;
10301026
p->keyword_trial = NULL;
10311027
#ifdef Py_DEBUG
10321028
p->debug = _Py_GetConfig()->parser_debug;
@@ -1052,10 +1048,6 @@ _PyPegen_Parser_Free(Parser *p)
10521048
static void
10531049
reset_parser_state_for_error_pass(Parser *p)
10541050
{
1055-
p->last_stmt_location.lineno = 0;
1056-
p->last_stmt_location.col_offset = 0;
1057-
p->last_stmt_location.end_lineno = 0;
1058-
p->last_stmt_location.end_col_offset = 0;
10591051
for (int i = 0; i < p->fill; i++) {
10601052
p->tokens[i]->memo = NULL;
10611053
p->tokens[i]->memo_mask = 0;
@@ -1432,7 +1424,7 @@ _PyPegen_run_parser_from_file_pointer(FILE *fp, int start_rule, PyObject *filena
14321424
Py_DECREF(module);
14331425

14341426
Parser *p = _PyPegen_Parser_New(tok, start_rule, parser_flags, PY_MINOR_VERSION,
1435-
errcode, NULL, arena);
1427+
errcode, arena);
14361428
if (p == NULL) {
14371429
goto error;
14381430
}
@@ -1493,7 +1485,7 @@ _PyPegen_run_parser_from_string(const char *str, int start_rule, PyObject *filen
14931485
int feature_version = flags && (flags->cf_flags & PyCF_ONLY_AST) ?
14941486
flags->cf_feature_version : PY_MINOR_VERSION;
14951487
Parser *p = _PyPegen_Parser_New(tok, start_rule, parser_flags, feature_version,
1496-
NULL, str, arena);
1488+
NULL, arena);
14971489
if (p == NULL) {
14981490
goto error;
14991491
}

‎Parser/pegen.h‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,6 @@ typedef struct {
7171
size_t num_items;
7272
} growable_comment_array;
7373

74-
typedef struct {
75-
int lineno;
76-
int col_offset;
77-
int end_lineno;
78-
int end_col_offset;
79-
} location;
80-
8174
typedef struct {
8275
int budget;
8376
int furthest;
@@ -111,7 +104,6 @@ typedef struct {
111104
int call_invalid_rules;
112105
KeywordTrial *keyword_trial;
113106
int debug;
114-
location last_stmt_location;
115107
IdentifierCacheEntry *identifier_cache;
116108
PyThreadState *tstate;
117109
// Cached copy of tstate->c_stack_soft_limit offset by one margin toward
@@ -433,12 +425,10 @@ stmt_ty _PyPegen_checked_from_import(Parser *p, asdl_seq *dots, expr_ty module_n
433425
asdl_alias_seq *names, expr_ty lazy_token, int lineno,
434426
int col_offset, int end_lineno, int end_col_offset,
435427
PyArena *arena);
436-
asdl_stmt_seq* _PyPegen_register_stmts(Parser *p, asdl_stmt_seq* stmts);
437-
stmt_ty _PyPegen_register_stmt(Parser *p, stmt_ty s);
438428

439429
// Parser API
440430

441-
Parser *_PyPegen_Parser_New(struct tok_state *, int, int, int, int *, const char*, PyArena *);
431+
Parser *_PyPegen_Parser_New(struct tok_state *, int, int, int, int *, PyArena *);
442432
void _PyPegen_Parser_Free(Parser *);
443433
mod_ty _PyPegen_run_parser_from_file_pointer(FILE *, int, PyObject *, const char *,
444434
const char *, const char *, PyCompilerFlags *, int *, PyObject **,

0 commit comments

Comments
 (0)