Nicer diagnostics for `python -m invalid-name`

And my prediction came true.

Having said that, in this case at least, I don’t see a downside. It would help for misspellings of stdlib modules as well:

$ python3.10 -m unitest spam.py
/usr/local/bin/python3.10: No module named unitest

We already have a mechanism for suggesting misspellings, which is applied to NameError, AttributeError, and at least some ImportError exceptions. We don’t have to limit suggestions to simple heuristics like “change hyphen to an underscore”, or worry about what is an identifier or not, which just do a string distance calculation with existing modules and return the closest match.

Technically this has an unbounded cost (say, you have a hundred thousand python modules in your PYTHONPATH) but unlike the import statement, there is unlikely to be much concern about speed when using runpy at the command line. And if necessary, we could implement a limit of (say) 500 modules per directory in the path.