Skip to content

Fix crash on failed attribute inference - #11372

Open
rootsec1 wants to merge 1 commit into
pylint-dev:mainfrom
rootsec1:fix/11356-inference-error
Open

Fix crash on failed attribute inference#11372
rootsec1 wants to merge 1 commit into
pylint-dev:mainfrom
rootsec1:fix/11356-inference-error

Conversation

@rootsec1

Copy link
Copy Markdown

Summary

  • handle InferenceError raised while resolving attributes for no-member
  • add a functional regression test for the metaclass lookup reproducer
  • add a bugfix news fragment

When attribute inference fails, the checker now skips that owner instead of aborting the lint run with astroid-error. This follows the existing behavior for other unresolved attribute owners and avoids introducing a false positive from incomplete inference.

Closes #11356

Tests

  • pytest -q tests/test_functional.py::test_functional[regression_11356] tests/checkers/unittest_typecheck.py
  • pytest -q (2158 passed, 314 skipped, 5 xfailed)
  • pre-commit run --files pylint/checkers/typecheck.py tests/functional/r/regression_03/regression_11356.py tests/functional/r/regression_03/regression_11356.rc doc/whatsnew/fragments/11356.bugfix

Comment on lines +1209 to 1212
except (AttributeError, astroid.InferenceError):
continue
except astroid.DuplicateBasesError:
continue

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we just merge these then?

@github-actions

Copy link
Copy Markdown
Contributor

🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉

This comment was generated for commit 6d7524f

@HDPark95 HDPark95 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified: crash reproduces on b44f86a, gone at 6d7524f; reverting only typecheck.py fails the new test (astroid-error), so it is load-bearing.

On continue: with several inferred owners, skipping only the failing one can create a message.

class Meta(type): pass
class A(metaclass=Meta): a = 1
class B: pass
OBJ = A if random.random() > 0.5 else B
print(OBJ.a)           # clean without the line below
for Meta.a in _: pass  # -> E1101: Class 'B' has no 'a' member

return, as has_dynamic_getattr above does for the same reason, drops it, keeps #11356 fixed, suite unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uncaught InferenceError: Inference failed for all members of AssignAttr in types checker

3 participants