Skip to content

Commit

Permalink
Make sure to be able to deal with all kinds of loaders, fixes #1487
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhalter committed Jan 31, 2020
1 parent e930f47 commit e1425de
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions jedi/_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ def find_module_py33(string, path=None, loader=None, full_name=None, is_global_s


def _from_loader(loader, string):
is_package = loader.is_package(string)
try:
is_package_method = loader.is_package
except AttributeError:
is_package = False
else:
is_package = is_package_method(string)
try:
get_filename = loader.get_filename
except AttributeError:
Expand All @@ -123,7 +128,11 @@ def _from_loader(loader, string):

# To avoid unicode and read bytes, "overwrite" loader.get_source if
# possible.
f = type(loader).get_source
try:
f = type(loader).get_source
except AttributeError:
raise ImportError("get_source was not defined on loader")

if is_py3 and f is not importlib.machinery.SourceFileLoader.get_source:
# Unfortunately we are reading unicode here, not bytes.
# It seems hard to get bytes, because the zip importer
Expand Down

0 comments on commit e1425de

Please sign in to comment.