Rewrite py__package__ to return a list

This commit is contained in:
Dave Halter
2019-03-18 10:01:18 +01:00
parent e2fea0a5de
commit 234f3d93cd
4 changed files with 6 additions and 6 deletions

View File

@@ -28,7 +28,7 @@ py__simple_getitem__(index: int/str) Returns a a set of types of the index.
py__getitem__(indexes: ContextSet) Returns a a set of types of the index. py__getitem__(indexes: ContextSet) Returns a a set of types of the index.
py__file__() Only on modules. Returns None if does py__file__() Only on modules. Returns None if does
not exist. not exist.
py__package__() Only on modules. For the import system. py__package__() -> List[str] Only on modules. For the import system.
py__path__() Only on modules. For the import system. py__path__() Only on modules. For the import system.
py__get__(call_object) Only on instances. Simulates py__get__(call_object) Only on instances. Simulates
descriptors. descriptors.

View File

@@ -181,9 +181,9 @@ class ModuleContext(ModuleMixin, TreeContext):
def py__package__(self): def py__package__(self):
if self._get_init_directory() is None: if self._get_init_directory() is None:
return re.sub(r'\.?[^.]+$', '', self.py__name__()) return re.sub(r'\.?[^.]+$', '', self.py__name__()).split('.')
else: else:
return self.py__name__() return self.string_names
def _py__path__(self): def _py__path__(self):
search_path = self.evaluator.get_sys_path() search_path = self.evaluator.get_sys_path()

View File

@@ -39,7 +39,7 @@ class ImplicitNamespaceContext(Context):
@property @property
@evaluator_method_cache() @evaluator_method_cache()
def name(self): def name(self):
string_name = self.py__package__().rpartition('.')[-1] string_name = self.py__package__()[-1]
return ImplicitNSName(self, string_name) return ImplicitNSName(self, string_name)
def py__file__(self): def py__file__(self):
@@ -48,7 +48,7 @@ class ImplicitNamespaceContext(Context):
def py__package__(self): def py__package__(self):
"""Return the fullname """Return the fullname
""" """
return self._fullname return self._fullname.split('.')
def py__path__(self): def py__path__(self):
return self._paths return self._paths

View File

@@ -247,7 +247,7 @@ class Importer(object):
self._fixed_sys_path = None self._fixed_sys_path = None
self._inference_possible = True self._inference_possible = True
if level: if level:
base = module_context.py__package__().split('.') base = module_context.py__package__()
if base == [''] or base == ['__main__']: if base == [''] or base == ['__main__']:
base = [] base = []
# We need to care for two cases, the first one is if it's a valid # We need to care for two cases, the first one is if it's a valid