Skip to content

Commit 728bb3b

Browse files
committed
fix(python): a star import from __future__ is a parse barrier
The grammar rejects from __future__ import * as Python does, so the file carries an error node and its whole namespace is a PARSE unknown: a stronger barrier than the UNSUPPORTED statement the previous commit guarded for. That guard could never run and is dropped; the control asserts the parse barrier the parser actually yields. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 240b24a commit 728bb3b

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

‎internal/cbm/extract_imports.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,6 @@ static bool py_ns_import_fact(PyNamespaceBuilder *b, TSNode child, bool from,
600600
.module_name = module_name,
601601
.relative_level = level};
602602
if (from && strcmp(kind, "wildcard_import") == 0) {
603-
if (level == 0 && module_name && strcmp(module_name, "__future__") == 0)
604-
return false; /* a syntax error in Python: stays unsupported */
605603
f.kind = CBM_PY_NS_IMPORT_STAR;
606604
*out = f;
607605
return true;

‎tests/test_extraction.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12314,8 +12314,9 @@ TEST(python_namespace_facts_string_statements_and_future_imports) {
1231412314
{"concatenated f-string field", "from .impl import a\n\"x\" f\"{a!r}\"\n",
1231512315
CBM_PY_NS_REASON_EFFECT},
1231612316
{"call", "from .impl import a\nprint(a)\n", CBM_PY_NS_REASON_EFFECT},
12317+
/* Python rejects it, and so does the grammar: the whole file is unknown */
1231712318
{"star from __future__", "from .impl import a\nfrom __future__ import *\n",
12318-
CBM_PY_NS_REASON_UNSUPPORTED},
12319+
CBM_PY_NS_REASON_PARSE},
1231912320
};
1232012321
for (size_t i = 0; i < sizeof(barriers) / sizeof(barriers[0]); i++) {
1232112322
r = extract(barriers[i].source, CBM_LANG_PYTHON, "t", "pkg/__init__.py");

0 commit comments

Comments
 (0)