1
0
forked from VimPlug/jedi

Add a py__path__ method to the ModuleWrapper, that behaves very similar to a package's __path__ attribute.

This commit is contained in:
Dave Halter
2015-04-20 16:21:00 +02:00
parent df9452f210
commit 77a37be83a
2 changed files with 34 additions and 7 deletions

View File

@@ -30,6 +30,7 @@ __
"""
import os
import pkgutil
import imp
from itertools import chain
from jedi._compatibility import use_metaclass, unicode, Python3Method
@@ -762,6 +763,28 @@ class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module, Wrapper)):
def py__name__(self):
return self._evaluator.module_name_cache[self]
def py__file__(self):
return self._module.path
@property
def py__path__(self):
"""
In case of a package, this returns Python's __path__ attribute, which
is a list of paths (strings).
Raises an AttributeError if the module is not a package.
"""
def return_value():
return [path]
for suffix, _, _ in imp.get_suffixes():
ending = '__init__' + suffix
if self.py__file__().endswith(ending):
# Remove the ending, including the separator.
path = self.py__file__()[:-len(ending) - 1]
return return_value
else:
raise AttributeError('Only packages have __path__ attributes.')
@memoize_default()
def _sub_modules_dict(self):
"""