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

Fix getattr inference with empty annotation assignments #1834

Merged
merged 1 commit into from Oct 17, 2022

Conversation

cdce8p
Copy link
Member

@cdce8p cdce8p commented Oct 16, 2022

Description

Don't exit with AttributeInferenceError for annotation assignments if parent class contains valid assignment.

class Parent:
    attr: int = 2

class Child(Parent):
    attr: int

Type of Changes

Type
🐛 Bug fix

Related Issue

Refs pylint-dev/pylint#7631

@coveralls
Copy link

coveralls commented Oct 16, 2022

Pull Request Test Coverage Report for Build 3260984270

  • 7 of 7 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.0007%) to 92.272%

Totals Coverage Status
Change from base Build 3256664109: 0.0007%
Covered Lines: 9862
Relevant Lines: 10688

💛 - Coveralls

name: str,
context: InferenceContext | None = None,
class_context: bool = True,
) -> list[NodeNG]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure about this? I belive locals is actually SuccesfulInferenceResult but typed incorrectly currently...

Copy link
Member Author

Choose a reason for hiding this comment

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

I belive locals is actually SuccesfulInferenceResult but typed incorrectly currently...

Don't think so. AFAICT locals is only modified via set_local which takes a NodeNG argument. Thus the typing should be correct. We can always come back to it if we discover that it's wrong later.
https://github.com/PyCQA/astroid/blob/a29ee0f3fbbe3aa580280c979d3f01b0146dd00f/astroid/nodes/scoped_nodes/mixin.py#L91-L103

Copy link
Collaborator

Choose a reason for hiding this comment

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

See comment in other issue. This is not always the case and I think the typing should be updated here.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Elegant refactor and upgrade of the typing at the same time 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants