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

Crash if numpy.py exists in project root #7868

Closed
tushar-deepsource opened this issue Nov 29, 2022 · 0 comments · Fixed by pylint-dev/astroid#1892
Closed

Crash if numpy.py exists in project root #7868

tushar-deepsource opened this issue Nov 29, 2022 · 0 comments · Fixed by pylint-dev/astroid#1892
Assignees
Labels
Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@tushar-deepsource
Copy link
Contributor

tushar-deepsource commented Nov 29, 2022

Bug description

If a numpy.py file exists somewhere, pylint will crash with AttributeError due to astroid trying to access numpy.version.version.

Code snippet:

import numpy

numpy.ndarray([1, 2, 3])

Configuration

No response

Command used

pylint asd.py

Pylint output

************* Module asd
asd.py:1:0: C0114: Missing module docstring (missing-module-docstring)
Exception on node <Call l.3 at 0x106b9b1f0> in file '/Users/tusharsadhwani/code/marvin-python/asd.py'
Traceback (most recent call last):
  File "/Users/tusharsadhwani/code/marvin-python/venv3/lib/python3.10/site-packages/astroid/inference_tip.py", line 38, in _inference_tip_cached
    result = _cache[func, node]
KeyError: (<function infer_numpy_ndarray at 0x1066349d0>, <Attribute.ndarray l.3 at 0x106b9b1c0>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/tusharsadhwani/code/marvin-python/venv3/lib/python3.10/site-packages/pylint/checkers/utils.py", line 1395, in infer_all
    return list(node.infer(context=context))
  File "/Users/tusharsadhwani/code/marvin-python/venv3/lib/python3.10/site-packages/astroid/nodes/node_ng.py", line 159, in infer
    results = list(self._explicit_inference(self, context, **kwargs))
  File "/Users/tusharsadhwani/code/marvin-python/venv3/lib/python3.10/site-packages/astroid/inference_tip.py", line 45, in _inference_tip_cached
    result = _cache[func, node] = list(func(*args, **kwargs))
  File "/Users/tusharsadhwani/code/marvin-python/venv3/lib/python3.10/site-packages/astroid/brain/brain_numpy_ndarray.py", line 141, in infer_numpy_ndarray
    if numpy_supports_type_hints():
  File "/Users/tusharsadhwani/code/marvin-python/venv3/lib/python3.10/site-packages/astroid/brain/brain_numpy_utils.py", line 20, in numpy_supports_type_hints
    np_ver = _get_numpy_version()
  File "/Users/tusharsadhwani/code/marvin-python/venv3/lib/python3.10/site-packages/astroid/brain/brain_numpy_utils.py", line 32, in _get_numpy_version
    return tuple(numpy.version.version.split("."))
AttributeError: module 'numpy' has no attribute 'version'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/tusharsadhwani/code/marvin-python/venv3/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 90, in walk
    callback(astroid)
  File "/Users/tusharsadhwani/code/marvin-python/venv3/lib/python3.10/site-packages/pylint/checkers/base/basic_error_checker.py", line 432, in visit_call
    for inferred in infer_all(node.func):
  File "/Users/tusharsadhwani/code/marvin-python/venv3/lib/python3.10/site-packages/pylint/checkers/utils.py", line 1399, in infer_all
    raise AstroidError from e
astroid.exceptions.AstroidError
asd.py:1:0: F0002: asd.py: Fatal error while checking 'asd.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in '/Users/tusharsadhwani/Library/Caches/pylint/pylint-crash-2022-11-29-20-05-08.txt'. (astroid-error)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

Expected behavior

No crash

Pylint version

pylint 2.15.7
astroid 2.12.13
Python 3.10.6 (main, Aug 30 2022, 04:58:14) [Clang 13.1.6 (clang-1316.0.21.2.5)]

OS / Environment

MacOS Monterey

Additional dependencies

No response

@tushar-deepsource tushar-deepsource added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Nov 29, 2022
@mbyrnepr2 mbyrnepr2 added Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Nov 29, 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 Needs astroid update Needs an astroid update (probably a release too) before being mergable Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants