from X import * does not compile
from math import * # v451: error: expected expression
Fix (compiler/pyparser.inc)
- The from-import name loops accept
*: the unit arm and the consumed-only arm (typing, collections, itertools...). PyNoteTopNameruns before each top-level statement of an imported module and consumes nothing. It notes the name adef,classorNAME =binds, when a builtin has that name, and the string items of__all__ = [...]/(...).PyStarImportRecordthen records those names for the importing unit, exactly as afrom X import lendoes (8878f1ea97'sPyImpName):- from
__all__when X defines one; - otherwise the names not starting with
_. A builtin X does not export stays the builtin.
- from
Measured (2026-09-29)
-
test/test_nilpy_from_import_star.npy, with helperstest/starmod_plain.pyandtest/starmod_all.py, covers:from math import *;- a user module's function, value and class, with its
lenshadowing the builtin; - an
__all__module whose listedmaxshadows the builtin and whose unlistedsumdoes not.
It equals CPython on x86-64, i386 and wasm32. The previous compiler refuses it on all three. Those three are the rows.
-
Probes that equal CPython:
from typing import *,from collections import *(Counter),from tkinter import *(compile and bind), a builtin-named class, andimport mstill not leaking m'ssum. -
Differential over the 472 tracked NilPy tests that import something, compiled and run with the compiler before and after: identical output and exit code for all 472. The note runs at every imported module's top level, which is why the quick tier was not enough.
Not covered (LOGBOOK)
- Members the compiler provides by call table rather than by a unit
(
random.seed,sys.argv,os.path.basename,itertools.count) are not bound by*. Their use sites fail at compile time with "undefined variable". PyStdlibCallProc is an if/else chain; making it a table that a star import can walk is the fix. - A name X does not export (
_hidden, or one left out of__all__) is still reachable through flat unit scope, where CPython raises NameError. A named from-import has the same difference.