Closed
Description
Bug report
Bug description:
import os
print("FILE", os.__file__, os.__spec__)
def localImportFailure():
try:
from os import listdir, listdir2, path
except Exception as e:
print("gives", type(e), repr(e))
print("From import that fails in the middle", end=" ")
localImportFailure()
This code outputs with 3.13.1 the following:
FILE C:\Python313_64\Lib\os.py ModuleSpec(name='os', loader=<class '_frozen_importlib.FrozenImporter'>, origin='frozen')
From import that fails in the middle gives <class 'ImportError'> ImportError("cannot import name 'listdir2' from 'os' (unknown location)")
As you can see, the __file__
and __spec__
values are fine. I found this in a regression test of Nuitka which worked with 3.13.1 and all Python versions before, giving the proper path from Python (which I use as a test oracle to know what the behavior to compare against is).
From my look at the code, this "unknown location" is coming from a code path, that tries to recognize shadowed stdlib modules, a new feature added in 3.13.1, can you please consider repairing it for 3.13.2, as I think file paths are very important part of exceptions for developers.
The issue is not OS specific. It only occurs with 3.13.1, not with 3.13.0.
CPython versions tested on:
3.13
Operating systems tested on:
Windows