Mishe ships new code to itself through a "moving pin": a release is only run after a checker confirms it can start. The checker has a rule that sounds obvious: the package must have an entry point, a __main__.py, so that python -m has something to run. For a while the rule was weaker than it looked, and it passed releases that did nothing when started.

Here is the failure, reproduced in a scratch directory with three versions of __main__.py and a one-function package:

  • from .cli import main alone: python -m pkg prints nothing and exits 0.
  • from .cli import main plus def _unused(): main(): prints nothing, exits 0.
  • from .cli import main plus main() at module level: prints hi, exits 0.

Exit 0 is the problem. A process that exits cleanly with no output looks healthy to any check that only reads the exit code. The first version of the checker tested that the file existed and held a statement. An import is a statement, so it passed.

Field review found these one by one. Each fix made the checker read the file as Python rather than as text:

  1. A missing __main__.py is RED, named in the detail. Before this, only __init__.py was tested.
  2. A comment-only or docstring-only entry point is RED, because nothing runs.
  3. An import-only entry point is RED. Importing a module runs its top level, but the file does not call anything.
  4. Calls inside an uncalled def or lambda do not count. The checker now walks only the nodes that run at import time.
  5. An inverted guard, such as if __name__ != '__main__':, is treated as code that does not run under python -m.
  6. A builtin name, such as help, is judged by what the module binds it to. A local assignment inside an uncalled function does not shadow it. A class body or comprehension does not either.

The fixes came with regression tests; the one for class bodies and comprehensions was shown to fail on the checker before it. The check's test file has 67 tests, and they pass on the current tree.

What the checker still cannot do is run the code. It reads the source and decides whether a call happens at import. That is a static judgement, so it can be wrong in a case nobody has written a test for. The runbook names the remaining limits. We would rather say that in the article than claim the checker proves a program works.

The general lesson for anyone building a gate: a check that reads a status code will pass a program that exits cleanly and does nothing. Ask what the check would say about the emptiest real input you can construct, and write that input down as a test before you trust the gate.