Skip to content

Prevent creating Instance that proxies another Instance when inferring __new__(cls) #1682

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

Merged
merged 6 commits into from
Jul 2, 2022

Conversation

jacobtylerwalls
Copy link
Member

Steps

  • For new features or bug fixes, add a ChangeLog entry describing what your PR does.
  • Write a good description on what the PR does.

Description

See discussion at pylint-dev/pylint#7109 (comment). When astroid thinks __new__(cls) is being called with an instance either due to user error or because of inference ambiguity (e.g. the library code in the OP used an isinstance guard that astroid doesn't cope with), we now raise InferenceError instead of creating a bogus Instance-proxied-to-Instance. Callers then transform this to Uninferable as appropriate. (See #782 for a precedent.)

Type of Changes

Type
🐛 Bug fix

Related Issue

Refs pylint-dev/pylint#7109

@coveralls
Copy link

coveralls commented Jul 2, 2022

Pull Request Test Coverage Report for Build 2602639973

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

Totals Coverage Status
Change from base Build 2595507463: 0.005%
Covered Lines: 9420
Relevant Lines: 10227

💛 - Coveralls

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.

LGTM, just a question for my information :)

@jacobtylerwalls
Copy link
Member Author

This is going to be too difficult to backport; bumping to 2.12.

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

Last two nits!

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

@jacobtylerwalls
Copy link
Member Author

Thanks for the initial digging and the review! ✨

@Pierre-Sassoulas
Copy link
Member

There's two issues left in 2.12, including this one that is mergeable, should we even release 2.11.7 ?

@DanielNoord
Copy link
Collaborator

I'd like to get the is None in 2.12 if possible. It was moved to 2.13 recently, but the last reviews don't look like they should take too long to resolve.

@jacobtylerwalls jacobtylerwalls merged commit dd80a68 into pylint-dev:main Jul 2, 2022
@jacobtylerwalls jacobtylerwalls deleted the chained-instance branch July 2, 2022 22:25
@DanielNoord
Copy link
Collaborator

This has created an issue for nodes.Const as it can no longer call the __init__ of Instance. We set the ._proxied of Const during bootstrapping.

I'm looking into a solution.

@DanielNoord
Copy link
Collaborator

See #1689.

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

Successfully merging this pull request may close these issues.

4 participants