mirror of
https://github.com/python/cpython.git
synced 2025-07-30 06:34:15 +00:00
[3.13] gh-125331: Allow the parser to activate future imports on the fly (GH-125482) (#131062)
gh-125331: Allow the parser to activate future imports on the fly (GH-125482)
(cherry picked from commit 3bd3e09588
)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit is contained in:
parent
977af3a6a2
commit
ebd2ed7ad8
6 changed files with 50 additions and 2 deletions
|
@ -1685,3 +1685,18 @@ _PyPegen_concatenate_strings(Parser *p, asdl_expr_seq *strings,
|
|||
assert(current_pos == n_elements);
|
||||
return _PyAST_JoinedStr(values, lineno, col_offset, end_lineno, end_col_offset, p->arena);
|
||||
}
|
||||
|
||||
stmt_ty
|
||||
_PyPegen_checked_future_import(Parser *p, identifier module, asdl_alias_seq * names, int level,
|
||||
int lineno, int col_offset, int end_lineno, int end_col_offset,
|
||||
PyArena *arena) {
|
||||
if (level == 0 && PyUnicode_CompareWithASCIIString(module, "__future__") == 0) {
|
||||
for (Py_ssize_t i = 0; i < asdl_seq_LEN(names); i++) {
|
||||
alias_ty alias = asdl_seq_GET(names, i);
|
||||
if (PyUnicode_CompareWithASCIIString(alias->name, "barry_as_FLUFL") == 0) {
|
||||
p->flags |= PyPARSE_BARRY_AS_BDFL;
|
||||
}
|
||||
}
|
||||
}
|
||||
return _PyAST_ImportFrom(module, names, level, lineno, col_offset, end_lineno, end_col_offset, arena);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue