Issue 46902: Typo hint message for from-imports? (original) (raw)
See for example:
from pygments.regexopt import regexopt Traceback (most recent call last): File "", line 1, in ImportError: cannot import name 'regexopt' from 'pygments.regexopt' (/home/jean/repos/pygments/pygments/regexopt.py) from pygments.regexopt import regex_opt regexopt Traceback (most recent call last): File "", line 1, in NameError: name 'regexopt' is not defined. Did you mean: 'regex_opt'?
In Python 3.10, there is a nice helpful error message suggesting how to correct the typo for NameError and AttributeError. Would it be possible to have the same for ImportError with 'from import'?
I evaluated this, but is considerably more complex than the regular import, because one triggers an attribute error where we have the full module but in the second case we don't have the full module ready, so it requires considerable modifications.
I will investigate again if there is a way that doesn't require lots of changes, but is likely that we unfortunately need to reject this improvement :(