From 4d3f314baacd73222de869fba37fd6f2e86d410e Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 24 Jan 2020 13:01:54 +0100 Subject: [PATCH] Create CompiledModule to have a better differentiation between compiled modules and compiles values --- jedi/inference/compiled/value.py | 57 ++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/jedi/inference/compiled/value.py b/jedi/inference/compiled/value.py index ccc24cf9..a2d67a74 100644 --- a/jedi/inference/compiled/value.py +++ b/jedi/inference/compiled/value.py @@ -86,32 +86,12 @@ class CompiledObject(Value): for access in self.access_handle.py__bases__() ) - def py__path__(self): - paths = self.access_handle.py__path__() - if paths is None: - return None - return map(cast_path, paths) - - def is_package(self): - return self.py__path__() is not None - - @property - def string_names(self): - # For modules - name = self.py__name__() - if name is None: - return () - return tuple(name.split('.')) - def get_qualified_names(self): return self.access_handle.get_qualified_names() def py__bool__(self): return self.access_handle.py__bool__() - def py__file__(self): - return cast_path(self.access_handle.py__file__()) - def is_class(self): return self.access_handle.is_class() @@ -298,11 +278,7 @@ class CompiledObject(Value): def get_metaclasses(self): return NO_VALUES - file_io = None # For modules - def _as_context(self): - if self.parent_context is None: - return CompiledModuleContext(self) return CompiledContext(self) @property @@ -316,6 +292,33 @@ class CompiledObject(Value): ] +class CompiledModule(CompiledObject): + file_io = None # For modules + + def _as_context(self): + return CompiledModuleContext(self) + + def py__path__(self): + paths = self.access_handle.py__path__() + if paths is None: + return None + return map(cast_path, paths) + + def is_package(self): + return self.py__path__() is not None + + @property + def string_names(self): + # For modules + name = self.py__name__() + if name is None: + return () + return tuple(name.split('.')) + + def py__file__(self): + return cast_path(self.access_handle.py__file__()) + + class CompiledName(AbstractNameDefinition): def __init__(self, inference_state, parent_value, name): self._inference_state = inference_state @@ -624,4 +627,8 @@ def create_from_access_path(inference_state, access_path): @inference_state_function_cache() def create_cached_compiled_object(inference_state, access_handle, parent_context): assert not isinstance(parent_context, CompiledObject) - return CompiledObject(inference_state, access_handle, parent_context) + if parent_context is None: + cls = CompiledModule + else: + cls = CompiledObject + return cls(inference_state, access_handle, parent_context)