You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Autoprofile fails if submodule contains a .py with with an invalid module name. #395
I saved a file "foo-v1.py" into a utils directory and that broke autoprofiling, as it recognized it as a Python file and tried to import it, but "foo-v1" is not a valid module name. A fix would be checking that the file has valid module name characters. We could also skip importing files that fail to import.
Sorry for the radio silence on this issue, was busy with #391 last week and my vacation the week before.
Frankly I was caught by surprise, I'd have guessed that invalid module names should've been excluded by default. But it seems that both static analysis and pkgutil are all too happy to leave them be, and so we end up with stuff like
try:
importmypkg.utils.foo-v1# This is syntactically invalidexceptImportError: # This normally handles failed imports
...
else: # This handles the profiling of module contents upon successful import
...
in the module written by line_profiler.autoprofile.eager_preimports.write_eager_import_module().
Activity
TTsangSC commentedon Aug 30, 2025
Sorry for the radio silence on this issue, was busy with #391 last week and my vacation the week before.
Frankly I was caught by surprise, I'd have guessed that invalid module names should've been excluded by default. But it seems that both static analysis and
pkgutilare all too happy to leave them be, and so we end up with stuff likein the module written by
line_profiler.autoprofile.eager_preimports.write_eager_import_module().I've since pushed a fix at #397.