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

(bugfix) Issue 10100: [C1802] should not be emitted for generators. #10107

Merged
merged 5 commits into from
Dec 3, 2024

Conversation

nedelcu-ioan
Copy link
Contributor

@nedelcu-ioan nedelcu-ioan commented Dec 3, 2024

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Refs #10100

@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code backport maintenance/3.3.x labels Dec 3, 2024
@Pierre-Sassoulas Pierre-Sassoulas added this to the 3.3.3 milestone Dec 3, 2024
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests βœ…

Project coverage is 95.80%. Comparing base (55098c7) to head (2432c93).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #10107      +/-   ##
==========================================
- Coverage   95.80%   95.80%   -0.01%     
==========================================
  Files         174      174              
  Lines       18973    18972       -1     
==========================================
- Hits        18177    18176       -1     
  Misses        796      796              
Files with missing lines Coverage Ξ”
...heckers/refactoring/implicit_booleaness_checker.py 100.00% <100.00%> (ΓΈ)

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, thank you ! Can you add a changelog in doc/whatsnew/fragments, please ?

pylint/checkers/refactoring/implicit_booleaness_checker.py Outdated Show resolved Hide resolved

This comment has been minimized.

This comment has been minimized.

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.

Closing #10100 should be done in a follow-up MR so we can have it in 4.0 and not when backporting this FP fix in 3.3.3. Which is why I'm approving / merging as is.

Fix a false positive for `use-implicit-booleaness-not-len`. No lint should be emitted for
generators (`len` is not defined for generators).

Closes #10100
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Closes #10100
Refs #10100

I feel like to close #10100 a message should be raised about the type error (add the if isinstance(len_arg, (nodes.GeneratorExp)): condition and raise the proper message in this case), because nothing is raised at the moment. But I don't know what to use in the existing list of message (probably should create a new message like "invalid-len-call" ?). What do everyone think ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could certainly perform the check within the current ImplicitBooleanessChecker, but I believe it would make more sense to create a dedicated checker for invalid uses of len. The reason for this is that raising an invalid-len-call message in a class designed for ImplicitBooleaness might lead to confusion or unnecessary coupling of unrelated concerns. By creating a separate checker, we can more clearly handle cases in which len is used improperly while keeping the scope of the existing checker focused on its intended task.

Copy link
Contributor Author

@nedelcu-ioan nedelcu-ioan Dec 4, 2024

Choose a reason for hiding this comment

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

Should I implement the new checker, maybe adding it to pylint/checkers with the name invalid_calls.py?

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for proposing. It's an error level message so it could should (?) be in a builtin checker really (BasicErrorChecker maybe ?). What do @jacobtylerwalls or @DanielNoord think ?

Copy link
Contributor

github-actions bot commented Dec 3, 2024

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

This comment was generated for commit 2432c93

@Pierre-Sassoulas Pierre-Sassoulas merged commit a4e91d7 into pylint-dev:main Dec 3, 2024
44 checks passed
@Pierre-Sassoulas
Copy link
Member

Congratulation on becoming a pylint contributor ;) !

github-actions bot pushed a commit that referenced this pull request Dec 3, 2024
Co-authored-by: Nedelcu <Nedelcu Ioan-Andrei>
Co-authored-by: Pierre Sassoulas <[email protected]>
(cherry picked from commit a4e91d7)
Pierre-Sassoulas pushed a commit that referenced this pull request Dec 4, 2024
#10109)

Co-authored-by: Nedelcu <Nedelcu Ioan-Andrei>
Co-authored-by: Pierre Sassoulas <[email protected]>
(cherry picked from commit a4e91d7)

Co-authored-by: Nedelcu Ioan-Andrei <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport maintenance/3.3.x 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.

2 participants