mirror of
https://github.com/JakeHillion/drgn.git
synced 2024-12-23 09:43:06 +00:00
drgndoc: support relative imports
Mainly for completeness, as I don't really like using them in my own projects. Signed-off-by: Omar Sandoval <osandov@osandov.com>
This commit is contained in:
parent
a270525f8b
commit
192d35c609
@ -112,16 +112,18 @@ class Namespace:
|
||||
break
|
||||
|
||||
if isinstance(node, (Import, ImportFrom)):
|
||||
modules.clear()
|
||||
classes.clear()
|
||||
if isinstance(node, Import):
|
||||
import_name = node.module
|
||||
modules.clear()
|
||||
elif isinstance(node, ImportFrom):
|
||||
if node.module is None or node.level != 0:
|
||||
raise NotImplementedError("TODO: relative imports")
|
||||
import_name = node.module
|
||||
if node.level >= len(modules):
|
||||
# Relative import beyond top-level package. Bail.
|
||||
break
|
||||
# Absolute import is level 0, which clears the whole list.
|
||||
del modules[-node.level :]
|
||||
name_components.append(node.name)
|
||||
name_components.extend(reversed(import_name.split(".")))
|
||||
if node.module is not None:
|
||||
name_components.extend(reversed(node.module.split(".")))
|
||||
elif name_components:
|
||||
if isinstance(node, Module):
|
||||
assert not classes
|
||||
|
Loading…
Reference in New Issue
Block a user