summaryrefslogtreecommitdiff
path: root/astroid
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2021-10-17 10:04:16 +0200
committerGitHub <noreply@github.com>2021-10-17 10:04:16 +0200
commitabfad38e1a2acba0bcdda217c8fdbe0382c7268f (patch)
tree0ccaf772e862cfd5ade7fed802380d4bc264ae45 /astroid
parentb2f57b7e5e49253c69bd7335999b20fea9e3633a (diff)
downloadastroid-git-abfad38e1a2acba0bcdda217c8fdbe0382c7268f.tar.gz
Fix regression with import resolver (#1211)
* Fix regression with import resolver Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'astroid')
-rw-r--r--astroid/nodes/scoped_nodes.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/astroid/nodes/scoped_nodes.py b/astroid/nodes/scoped_nodes.py
index 4559fc55..61bb0794 100644
--- a/astroid/nodes/scoped_nodes.py
+++ b/astroid/nodes/scoped_nodes.py
@@ -708,19 +708,16 @@ class Module(LocalsDictNodeNG):
raise
return AstroidManager().ast_from_module_name(modname)
- def relative_to_absolute_name(self, modname, level):
+ def relative_to_absolute_name(self, modname: str, level: int) -> str:
"""Get the absolute module name for a relative import.
The relative import can be implicit or explicit.
:param modname: The module name to convert.
- :type modname: str
:param level: The level of relative import.
- :type level: int
:returns: The absolute module name.
- :rtype: str
:raises TooManyLevelsError: When the relative import refers to a
module too far above this one.
@@ -734,8 +731,12 @@ class Module(LocalsDictNodeNG):
if self.package:
level = level - 1
package_name = self.name.rsplit(".", level)[0]
- elif not os.path.exists("__init__.py") and os.path.exists(
- modname.split(".")[0]
+ elif (
+ self.path
+ and not os.path.exists(os.path.dirname(self.path[0]) + "/__init__.py")
+ and os.path.exists(
+ os.path.dirname(self.path[0]) + "/" + modname.split(".")[0]
+ )
):
level = level - 1
package_name = ""