Skip to content

Commit ee3aeaa

Browse files
Fix module name for files not on sys.path
_path_to_module included the root separator (/ or drive letter) when converting absolute paths to dotted module names, producing /.tmp.project.main instead of tmp.project.main.
1 parent 9b17680 commit ee3aeaa

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Lib/profiling/sampling/module_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ def _path_to_module(path):
112112
if path.suffix == '.py':
113113
path = path.with_suffix('')
114114

115-
# Convert path separators to dots
116-
parts = path.parts
115+
# Convert path separators to dots, stripping root/drive (e.g. "/" or "C:\")
116+
parts = [p for p in path.parts if p != path.root and p != path.drive]
117117

118118
# Handle __init__ files - they represent the package itself
119119
if parts and parts[-1] == '__init__':

0 commit comments

Comments
 (0)