check_purity allows __future__ only as an absolute import's module, and reads an import's names once (#600)

Merged
DO
10d ago
+22-3

Closes #600.

What changes

In tools/check_purity.py, _special refuses a name written __x__ anywhere in the Kernel's syntax tree, except as the module of from __future__ import. This PR closes the three gaps the last reads of #599 found:

  1. A relative __future__ is refused. The exemption now holds only when the import is absolute (not node.level). So from .__future__ import g, which names a Kernel module, is refused like from kernel.__future__ import g.
  2. __future__ is refused outside an import's module. New boundary cases: def f(__future__): and from kernel.terms import run as __future__.
  3. An import's names are read once. A new assertion checks that from kernel.terms import __dict__ as ns gives exactly one problem naming __dict__, at x.py:1.

The new cases are in tests/test_tools.py::Purity.test_the_kernel_calls_nothing_it_is_given. Three mutants are added under "Issue 600", and one existing mutant is repointed to the changed line:

MutantMain's testThis test
a relative future is the one allowedsurviveskilled
future is allowed wherever it is namedsurviveskilled
an import's names are read twicesurviveskilled

No record: decision 0155 already allows only from __future__ import, and this makes the check hold to it. No protected path is touched.

Verify

Pending.

Reviews

ReadState
Claude + securitypending
Argonpending
Musenot run (quota); owed after 2026-11-09
Astranot run (quota)
Codexautomatic on push

šŸ¤– Generated with Claude Code