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 #3675: safe_infer() finds ambiguity among function definitions when number of arguments differ #5409

Merged
merged 4 commits into from
Dec 14, 2021

Conversation

jacobtylerwalls
Copy link
Member

@jacobtylerwalls jacobtylerwalls commented Nov 27, 2021

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Before
safe_infer might confuse two function definitions having different numbers of arguments.

Now
It won't. But there is an inference problem with TemporaryFile being inferred as NamedTemporaryFile, which has an extra argument (delete), so I special-cased it. Is that an Astroid issue? Update: the way tempfile defines the name TemporaryFile conditionally based on platform means Astroid finds ambiguity.

Closes #3675

@coveralls
Copy link

coveralls commented Nov 27, 2021

Pull Request Test Coverage Report for Build 1541232939

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • 23 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.003%) to 93.697%

Files with Coverage Reduction New Missed Lines %
pylint/checkers/variables.py 9 95.51%
pylint/checkers/refactoring/refactoring_checker.py 14 98.16%
Totals Coverage Status
Change from base Build 1537239928: 0.003%
Covered Lines: 14166
Relevant Lines: 15119

πŸ’› - Coveralls

@jacobtylerwalls jacobtylerwalls changed the title Fix #3675: safe_infer now finds ambiguity when number of arguments differ Fix #3675: safe_infer now finds ambiguity among function definitions when number of arguments differ Nov 27, 2021
@jacobtylerwalls jacobtylerwalls changed the title Fix #3675: safe_infer now finds ambiguity among function definitions when number of arguments differ Fix #3675: safe_infer() finds ambiguity among function definitions when number of arguments differ Nov 27, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.13.0 milestone Nov 29, 2021
TemporaryFile may or may not be NamedTemporaryFile depending on system platform, and astroid has no way of knowing this, so abort.
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.

Nice fix! Two minor comments :)

Co-authored-by: DaniΓ«l van Noord <[email protected]>
@DanielNoord DanielNoord added the Needs astroid update Needs an astroid update (probably a release too) before being mergable label Dec 4, 2021
@DanielNoord DanielNoord added False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Needs astroid update Needs an astroid update (probably a release too) before being mergable labels Dec 5, 2021
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.

With that discussion solved, this is now good to go!

Thanks @jacobtylerwalls, also for pointing to the code that relied on args being None!

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.

Thank you for also making astroid better !

@DanielNoord
Copy link
Collaborator

@Pierre-Sassoulas I think this can be merged? Or are we waiting on something?

@Pierre-Sassoulas
Copy link
Member

I probably thought Marc would want to review, but we can merge, most MR do not have 3 approbations.

@Pierre-Sassoulas Pierre-Sassoulas merged commit 1f1c7b9 into pylint-dev:main Dec 14, 2021
@jacobtylerwalls jacobtylerwalls deleted the ticket_3675 branch December 14, 2021 13:33
cdce8p added a commit to cdce8p/pylint that referenced this pull request Feb 6, 2022
* Add additional isinstance check
* Originally added in pylint-dev#5409
Pierre-Sassoulas pushed a commit that referenced this pull request Feb 6, 2022
* Add additional isinstance check
* Originally added in #5409
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect number of arguments reported when function is imported over
5 participants