Skip to content

Commit d81bfb4

Browse files
authored
[Fix] Do no cache unknown packages. (#45)
Summary: Do no cache unknown packages when `__path__` is unexpected. Follow up of #43. Test Plan: All tests Reviewed-by: - Issue: (related) lark-parser/lark#1338
1 parent a14de6d commit d81bfb4

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/cds/dump.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def wrap_exec_module(self, module):
4242
getattr(module, i, None) for i in
4343
('__package__', '__file__', '__path__')
4444
)
45+
err = False
4546
# __path__ must be an iterable of strings,
4647
# we convert any valid __path__ to tuple of strings.
4748
# Ref: https://docs.python.org/3/reference/import.html#module-path
@@ -50,17 +51,16 @@ def wrap_exec_module(self, module):
5051
elif isinstance(path, str):
5152
# Some package might change this, which is non-standard.
5253
# There is no correct way to handle this.
53-
# We retain the file location to maintain the original import function,
54-
# and also record the `path` for debugging purposes.
55-
import os.path
56-
path = (os.path.dirname(file), path)
54+
# Do not cache this.
55+
err = True
5756
else:
5857
try:
5958
path = tuple(path)
6059
except TypeError:
6160
_verbose(f"{name}.__path__ is not iterable: {path}", 1)
62-
path = None
63-
meta_map[name] = (package, file, path)
61+
err = True
62+
if not err:
63+
meta_map[name] = (package, file, path)
6464
return module
6565

6666
return wrap_exec_module

0 commit comments

Comments
 (0)