Skip to content

Commit

Permalink
[Fix] Do no cache unknown packages. (#45)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
oraluben authored Oct 12, 2023
1 parent a14de6d commit d81bfb4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/cds/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def wrap_exec_module(self, module):
getattr(module, i, None) for i in
('__package__', '__file__', '__path__')
)
err = False
# __path__ must be an iterable of strings,
# we convert any valid __path__ to tuple of strings.
# Ref: https://docs.python.org/3/reference/import.html#module-path
Expand All @@ -50,17 +51,16 @@ def wrap_exec_module(self, module):
elif isinstance(path, str):
# Some package might change this, which is non-standard.
# There is no correct way to handle this.
# We retain the file location to maintain the original import function,
# and also record the `path` for debugging purposes.
import os.path
path = (os.path.dirname(file), path)
# Do not cache this.
err = True
else:
try:
path = tuple(path)
except TypeError:
_verbose(f"{name}.__path__ is not iterable: {path}", 1)
path = None
meta_map[name] = (package, file, path)
err = True
if not err:
meta_map[name] = (package, file, path)
return module

return wrap_exec_module
Expand Down

0 comments on commit d81bfb4

Please sign in to comment.