Skip to content

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

Merged
Pierre-Sassoulas merged 5 commits intopylint-dev:mainfrom
nedelcu-ioan:main
Dec 3, 2024
Merged

(bugfix) Issue 10100: [C1802] should not be emitted for generators.#10107
Pierre-Sassoulas merged 5 commits intopylint-dev:mainfrom
nedelcu-ioan:main

Conversation

@nedelcu-ioan
Copy link
Copy Markdown
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/4.0.x labels Dec 3, 2024
@Pierre-Sassoulas Pierre-Sassoulas added this to the 3.3.3 milestone Dec 3, 2024
@codecov
Copy link
Copy Markdown

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 382 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%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
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 ?

Comment thread pylint/checkers/refactoring/implicit_booleaness_checker.py Outdated
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 ?

@github-actions
Copy link
Copy Markdown
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
@Pierre-Sassoulas
Copy link
Copy Markdown
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 <pierre.sassoulas@gmail.com>
(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 <pierre.sassoulas@gmail.com>
(cherry picked from commit a4e91d7)

Co-authored-by: Nedelcu Ioan-Andrei <138256980+nedelcu-ioan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backported 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