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 with .AstroidError when parsing a dict with a lambda as the key #7453

Closed
Tomalak opened this issue Sep 11, 2022 · 1 comment · Fixed by #7454
Closed

Crash with .AstroidError when parsing a dict with a lambda as the key #7453

Tomalak opened this issue Sep 11, 2022 · 1 comment · Fixed by #7454
Assignees
Labels
Crash 💥 A bug that makes pylint crash Regression
Milestone

Comments

@Tomalak
Copy link

Tomalak commented Sep 11, 2022

Bug description

pylint crashes over this code

test.py

a = {
    (lambda x: print(x)): 'foo'
}

Configuration

No response

Command used

> pylint C:\test.py

Pylint output

************* Module test
test.py:3:0: C0304: Final newline missing (missing-final-newline)
test.py:1:0: C0114: Missing module docstring (missing-module-docstring)
Exception on node <Dict.dict l.1 at 0x1e448164df0> in file 'C:\test.py'
Traceback (most recent call last):
  File "C:\Python310\site-packages\pylint\utils\ast_walker.py", line 90, in walk
    callback(astroid)
  File "C:\Python310\site-packages\pylint\checkers\typecheck.py", line 2036, in visit_dict
    if not is_hashable(k):
  File "C:\Python310\site-packages\pylint\checkers\utils.py", line 1945, in is_hashable
    hash_fn = next(inferred.igetattr("__hash__"))
AttributeError: 'Lambda' object has no attribute 'igetattr'
test.py:1:0: F0002: test.py: Fatal error while checking 'test.py'. Please open an issue in our bug tracker so we address this [...]. (astroid-error)

-8<--------------------------------------------------------------------------

Traceback (most recent call last):
  File "C:\Python310\site-packages\pylint\lint\pylinter.py", line 782, in _lint_file
    check_astroid_module(module)
  File "C:\Python310\site-packages\pylint\lint\pylinter.py", line 1049, in check_astroid_module
    retval = self._check_astroid_module(
  File "C:\Python310\site-packages\pylint\lint\pylinter.py", line 1099, in _check_astroid_module
    walker.walk(node)
  File "C:\Python310\site-packages\pylint\utils\ast_walker.py", line 93, in walk
    self.walk(child)
  File "C:\Python310\site-packages\pylint\utils\ast_walker.py", line 93, in walk
    self.walk(child)
  File "C:\Python310\site-packages\pylint\utils\ast_walker.py", line 90, in walk
    callback(astroid)
  File "C:\Python310\site-packages\pylint\checkers\typecheck.py", line 2036, in visit_dict
    if not is_hashable(k):
  File "C:\Python310\site-packages\pylint\checkers\utils.py", line 1945, in is_hashable
    hash_fn = next(inferred.igetattr("__hash__"))
AttributeError: 'Lambda' object has no attribute 'igetattr'

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

Traceback (most recent call last):
  File "C:\Python310\site-packages\pylint\lint\pylinter.py", line 747, in _lint_files
    self._lint_file(fileitem, module, check_astroid_module)
  File "C:\Python310\site-packages\pylint\lint\pylinter.py", line 784, in _lint_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError

Expected behavior

No crash. :)

Pylint version

pylint 2.15.2
astroid 2.12.9
Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep  5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)]

OS / Environment

Windows 10

Additional dependencies

No response

@Tomalak Tomalak added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 11, 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 Sep 11, 2022
@jacobtylerwalls
Copy link
Member

Thanks for the report, regression in 1e2094d.

@jacobtylerwalls jacobtylerwalls added Regression Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning labels Sep 11, 2022
@jacobtylerwalls jacobtylerwalls self-assigned this Sep 11, 2022
@jacobtylerwalls jacobtylerwalls added this to the 2.15.3 milestone Sep 11, 2022
@jacobtylerwalls jacobtylerwalls removed the Needs PR This issue is accepted, sufficiently specified and now needs an implementation label Sep 11, 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 Regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants