contextl 1.2.30 → 1.2.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/python/import_parser.py +28 -4
package/package.json
CHANGED
package/python/import_parser.py
CHANGED
|
@@ -130,10 +130,31 @@ def _ts_imports_python(root: "Node") -> list[str]:
|
|
|
130
130
|
# from pathlib import Path
|
|
131
131
|
# from . import utils
|
|
132
132
|
# from ..models import User
|
|
133
|
+
rel_import = None
|
|
133
134
|
for child in node.children:
|
|
134
|
-
if child.type
|
|
135
|
-
|
|
136
|
-
break
|
|
135
|
+
if child.type == "relative_import":
|
|
136
|
+
rel_import = child.text.decode("utf-8", errors="replace")
|
|
137
|
+
break
|
|
138
|
+
|
|
139
|
+
if rel_import and rel_import.replace(".", "") == "":
|
|
140
|
+
# Bare relative import like `.` or `..`
|
|
141
|
+
seen_import = False
|
|
142
|
+
for child in node.children:
|
|
143
|
+
if child.type == "import":
|
|
144
|
+
seen_import = True
|
|
145
|
+
elif seen_import:
|
|
146
|
+
if child.type == "dotted_name":
|
|
147
|
+
results.append(f"{rel_import}{child.text.decode('utf-8', errors='replace')}")
|
|
148
|
+
elif child.type == "aliased_import":
|
|
149
|
+
for sub in child.children:
|
|
150
|
+
if sub.type == "dotted_name":
|
|
151
|
+
results.append(f"{rel_import}{sub.text.decode('utf-8', errors='replace')}")
|
|
152
|
+
break
|
|
153
|
+
else:
|
|
154
|
+
for child in node.children:
|
|
155
|
+
if child.type in ("dotted_name", "relative_import"):
|
|
156
|
+
results.append(child.text.decode("utf-8", errors="replace"))
|
|
157
|
+
break # only the module name, not the imported symbols
|
|
137
158
|
|
|
138
159
|
for child in node.children:
|
|
139
160
|
visit(child)
|
|
@@ -826,7 +847,10 @@ def parse_imports(scan_result: ScanResult) -> ParseResult:
|
|
|
826
847
|
for sym in symbols_str.split(','):
|
|
827
848
|
sym = sym.split(' as ')[0].strip()
|
|
828
849
|
if sym and sym != '*':
|
|
829
|
-
|
|
850
|
+
if base.endswith("."):
|
|
851
|
+
extra.append(f"{base}{sym}")
|
|
852
|
+
else:
|
|
853
|
+
extra.append(f"{base}.{sym}")
|
|
830
854
|
# Merge without duplicates
|
|
831
855
|
seen = set(raw_imports)
|
|
832
856
|
for e in extra:
|