Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: No module named __future__.absolute_import #7555

Closed
kayhayen opened this issue Oct 3, 2022 · 1 comment
Closed

ImportError: No module named __future__.absolute_import #7555

kayhayen opened this issue Oct 3, 2022 · 1 comment
Labels
Crash 💥 A bug that makes pylint crash Duplicate 🐫 Duplicate of an already existing issue

Comments

@kayhayen
Copy link

kayhayen commented Oct 3, 2022

Bug description

When parsing the following file:

""" Wrapper around appdir from PyPI
We do not assume to be installed and fallback to an inline copy and if that
is not installed, we use our own code for best effort.
"""
from __future__ import absolute_import
import os
import tempfile
from .FileOperations import makePath
from .Importing import importFromInlineCopy
try:
    import appdirs  # pylint: disable=I0021,import-error
except ImportError:
    # We handle the case without inline copy too.
    appdirs = importFromInlineCopy("appdirs", must_exist=False)
_cache_dir = None
def getCacheDir():
    global _cache_dir  # singleton, pylint: disable=global-statement
    if _cache_dir is None:
        _cache_dir = os.getenv("NUITKA_CACHE_DIR")
        if _cache_dir:
            _cache_dir = os.path.expanduser(_cache_dir)
        elif appdirs is not None:
            _cache_dir = appdirs.user_cache_dir("Nuitka", None)
        else:
            _cache_dir = os.path.join(os.path.expanduser("~"), ".cache", "Nuitka")
        # For people that build with HOME set this, e.g. Debian.
        if _cache_dir.startswith(("/nonexistent/", "/sbuild-nonexistent/")):
            _cache_dir = os.path.join(tempfile.gettempdir(), "Nuitka")
        makePath(_cache_dir)
    return _cache_dir

pylint crashed with a AstroidError and with the following stacktrace:

Traceback (most recent call last):
  File "/home/hayen/.local/lib/python3.9/site-packages/astroid/modutils.py", line 590, in _spec_from_modpath
    found_spec = spec.find_spec(modpath, [context])
  File "/home/hayen/.local/lib/python3.9/site-packages/astroid/interpreter/_import/spec.py", line 392, in find_spec
    finder, spec = _find_spec_with_path(
  File "/home/hayen/.local/lib/python3.9/site-packages/astroid/interpreter/_import/spec.py", line 361, in _find_spec_with_path
    raise ImportError(f"No module named {'.'.join(module_parts)}")
ImportError: No module named __future__.absolute_import
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/hayen/.local/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 782, in _lint_file
    check_astroid_module(module)
  File "/home/hayen/.local/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1049, in check_astroid_module
    retval = self._check_astroid_module(
  File "/home/hayen/.local/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1099, in _check_astroid_module
    walker.walk(node)
  File "/home/hayen/.local/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 93, in walk
    self.walk(child)
  File "/home/hayen/.local/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 90, in walk
    callback(astroid)
  File "/home/hayen/.local/lib/python3.9/site-packages/pylint/checkers/imports.py", line 523, in visit_importfrom
    self._add_imported_module(node, f"{imported_module.name}.{name}")
  File "/home/hayen/.local/lib/python3.9/site-packages/pylint/checkers/imports.py", line 833, in _add_imported_module
    importedmodname = astroid.modutils.get_module_part(
  File "/home/hayen/.local/lib/python3.9/site-packages/astroid/modutils.py", line 438, in get_module_part
    file_from_modpath(
  File "/home/hayen/.local/lib/python3.9/site-packages/astroid/modutils.py", line 334, in file_from_modpath
    return file_info_from_modpath(modpath, path, context_file).location
  File "/home/hayen/.local/lib/python3.9/site-packages/astroid/modutils.py", line 384, in file_info_from_modpath
    return _spec_from_modpath(modpath, path, context)
  File "/home/hayen/.local/lib/python3.9/site-packages/astroid/modutils.py", line 593, in _spec_from_modpath
    found_spec = spec.find_spec(modpath, path)
  File "/home/hayen/.local/lib/python3.9/site-packages/astroid/interpreter/_import/spec.py", line 392, in find_spec
    finder, spec = _find_spec_with_path(
  File "/home/hayen/.local/lib/python3.9/site-packages/astroid/interpreter/_import/spec.py", line 354, in _find_spec_with_path
    spec = finder_instance.find_module(
  File "/home/hayen/.local/lib/python3.9/site-packages/astroid/interpreter/_import/spec.py", line 203, in find_module
    if util.is_namespace(modname) and modname in sys.modules:
  File "/home/hayen/.local/lib/python3.9/site-packages/astroid/interpreter/_import/util.py", line 42, in is_namespace
    found_spec = _find_spec_from_path(
  File "/usr/lib/python3.9/importlib/util.py", line 58, in _find_spec_from_path
    return _find_spec(name, path)
  File "<frozen importlib._bootstrap>", line 925, in _find_spec
  File "<frozen importlib._bootstrap_external>", line 1358, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1150, in __init__
  File "<frozen importlib._bootstrap_external>", line 1165, in _get_parent_path
AttributeError: module '__future__' has no attribute '__path__'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/home/hayen/.local/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 747, in _lint_files
    self._lint_file(fileitem, module, check_astroid_module)
  File "/home/hayen/.local/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 784, in _lint_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError

.
************* Module nuitka.utils.AppDirs
nuitka/utils/AppDirs.py:1 F0002 astroid-error nuitka/utils/AppDirs.py: Fatal error while checking 'nuitka/utils/AppDirs.py'. Please open an issue in our bug tracker so we address this.

Configuration

Configuration usage is explicitely avoided, see command line below.

Command used

--init-hook="import sys;sys.setrecursionlimit(1024*sys.getrecursionlimit())" --disable=I0011,I0012,no-init,bad-whitespace,bad-continuation,E1103,W0632,W1504,C0123,C0411,C0413,R0204,similar-code,cyclic-import,duplicate-code,deprecated-module,deprecated-method,deprecated-argument,assignment-from-none,ungrouped-imports,no-else-return,c-extension-no-member,inconsistent-return-statements,raise-missing-from,import-outside-toplevel,useless-object-inheritance,useless-return,assignment-from-no-return,redundant-u-string-prefix,consider-using-f-string,consider-using-dict-comprehension,unnecessary-lambda-assignment --enable=useless-suppression --msg-template="{path}:{line} {msg_id} {symbol} {obj} {msg}" --reports=no --persistent=no --method-rgx=[a-z_][a-zA-Z0-9_]{2,40}$ --module-rgx=.* --function-rgx=.* --variable-rgx=.* --argument-rgx=.* --dummy-variables-rgx=_.*|trace_collection --ignored-argument-names=_.*|trace_collection --const-rgx=.* --max-line-length=125 --no-docstring-rgx=.* --max-module-lines=6000 --min-public-methods=0 --max-public-methods=100 --max-args=11 --max-parents=13 --max-statements=50 --max-nested-blocks=10 --max-bool-expr=10 --score=no --rcfile=/dev/null --notes=


### Pylint output

```shell
nuitka/utils/AppDirs.py:1 F0002 astroid-error  nuitka/utils/AppDirs.py: Fatal error while checking 'nuitka/utils/AppDirs.py'. Please open an issue in our bug tracker so we address this.

Expected behavior

Not crash

Pylint version

pylint 2.15.3
astroid 2.12.10
Python 3.9.2 (default, Feb 28 2021, 17:03:44)

OS / Environment

Debian Buster Python with PyPI packages

Additional dependencies

No response

@kayhayen kayhayen added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Oct 3, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Oct 3, 2022
@jacobtylerwalls
Copy link
Member

Duplicate is now tracked at #7592

@jacobtylerwalls jacobtylerwalls closed this as not planned Won't fix, can't repro, duplicate, stale Oct 15, 2022
@jacobtylerwalls jacobtylerwalls added Duplicate 🐫 Duplicate of an already existing issue and removed Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning labels Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash 💥 A bug that makes pylint crash Duplicate 🐫 Duplicate of an already existing issue
Projects
None yet
Development

No branches or pull requests

3 participants