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 crash when an attribute node was used inside an unary op #8209

Merged
merged 2 commits into from
Feb 7, 2023

Conversation

Pierre-Sassoulas
Copy link
Member

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Closes #8207

@Pierre-Sassoulas Pierre-Sassoulas added the Crash πŸ’₯ A bug that makes pylint crash label Feb 7, 2023
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.16.2 milestone Feb 7, 2023
Copy link
Contributor

@clavedeluna clavedeluna left a comment

Choose a reason for hiding this comment

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

I was just writing a PR to fix this since I feel responsible for writing it! The real fix turns out to be

    def _get_start_value(self, node: nodes.NodeNG) -> tuple[int | None, Confidence]:
        inferred = utils.safe_infer(node)
        start_val = inferred.value if inferred else None
        return start_val, INFERENCE

when I initially wrote it I was just not as familiar with when to use inference so I was super conservative, but turns out this should handle all cases!

@clavedeluna
Copy link
Contributor

You'll also need to update the output .txt with my suggestion

@Pierre-Sassoulas
Copy link
Member Author

Isn't it better to not use inference all the time for performance ?

@codecov
Copy link

codecov bot commented Feb 7, 2023

Codecov Report

Merging #8209 (d933d3f) into main (7612939) will not change coverage.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #8209   +/-   ##
=======================================
  Coverage   95.45%   95.45%           
=======================================
  Files         177      177           
  Lines       18635    18635           
=======================================
  Hits        17788    17788           
  Misses        847      847           
Impacted Files Coverage Ξ”
pylint/checkers/refactoring/refactoring_checker.py 98.33% <100.00%> (ΓΈ)
pylint/checkers/base/basic_error_checker.py 95.51% <0.00%> (ΓΈ)

@clavedeluna
Copy link
Contributor

Isn't it better to not use inference all the time for performance ?

You'd know better than I :) but I guess here we're trading performance for preventing another one of these bugs in the future in case there is another type of node we didn't think of in the tests.

@Pierre-Sassoulas
Copy link
Member Author

I think at this point we pretty much covered all the crash cases, the issues are getting increasingly niche. But yeah it crashed a lot since initial implementation. πŸ˜„ What do you think ?

You'll also need to update the output .txt with my suggestion

I did not understand that part ?

@clavedeluna
Copy link
Contributor

I think at this point we pretty much covered all the crash cases, the issues are getting increasingly niche. But yeah it crashed a lot since initial implementation. πŸ˜„ What do you think ?

You'll also need to update the output .txt with my suggestion

I did not understand that part ?

No need to update anything since we've discussed it.

@Pierre-Sassoulas
Copy link
Member Author

I have no idea if the performance are better with the current code compared to inference tbh. And what you proposed looks a lot better and also fail proof.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2023

πŸ€– According to the primer, this change has no effect on the checked open source code. πŸ€–πŸŽ‰

This comment was generated for commit d933d3f

@Pierre-Sassoulas
Copy link
Member Author

@DanielNoord do you have an opinion on the subject ?

@DanielNoord
Copy link
Collaborator

This looks fine to me! I don't really unferstand the suggestion by @clavedeluna as .values still isn't safe, but this follows the pattern we normally use!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported Crash πŸ’₯ A bug that makes pylint crash
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash: AstroidError in refactoring_checker.py
3 participants