[python] PY-91830 handle the case when __file__ is pyc

- Python 3 - `__file__` is always `*.py`
- Python 2 - `__file__` could be `*.pyc`

if the file is `*.pyc` - `... in step_files` will fail, hence why the relevant test `test_only_step_modules_are_reimported` fails on Python 2


(cherry picked from commit 1ab51b37debb41df12b04a10ff0945b996b8c0ec)

IJ-MR-220056

GitOrigin-RevId: 9ff1aa5ffce90cc3eee4fa7b71ffa85bceadcd21
This commit is contained in:
Pavel Karateev
2026-08-26 21:51:02 +00:00
committed by intellij-monorepo-bot
parent 0d5ce4a978
commit a140cb8113
+5 -1
View File
@@ -107,7 +107,11 @@ def _modules_to_reimport(old_modules, step_files):
if name in old_modules or module is None:
continue
path = getattr(module, '__file__', None)
if not path or os.path.normcase(os.path.abspath(path)) not in step_files:
if not path:
continue
if path.endswith('.pyc'): # Python 2
path = path[:-1]
if os.path.normcase(os.path.abspath(path)) not in step_files:
continue
subtree = [name]
prefix = name + '.'