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

consider-using-generator error message ignores default arguments #8563

Closed
ioah86 opened this issue Apr 10, 2023 · 1 comment · Fixed by #8582 or #9093
Closed

consider-using-generator error message ignores default arguments #8563

ioah86 opened this issue Apr 10, 2023 · 1 comment · Fixed by #8582 or #9093
Labels
Documentation 📗 Minor 💅 Polishing pylint is always nice Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@ioah86
Copy link

ioah86 commented Apr 10, 2023

Bug description

The built-in min function of python has multiple ways of calling it, as described in the documentation.

While this

min([i for i in range(len(line)) if line[i] not in whitespaces])

does correctly trigger the pylint error, I am also getting the error for this

min([i for i in range(len(line)) if line[i] not in whitespaces], default=0)

There is no other way for no.2, and I think that the linter just does not take this way of calling min into account.

Configuration

No response

Command used

pylint src/hidden_type/util.py

Pylint output

************* Module src.hidden_type.util
src/hidden_type/util.py:523:14: R1728: Consider using a generator instead 'min(i for i in range(len(line)) if line[i] not in whitespaces)' (consider-using-generator)

------------------------------------------------------------------
Your code has been rated at 9.96/10 (previous run: 9.92/10, +0.04)

Expected behavior

No error.

Pylint version

pylint 2.17.2
astroid 2.15.2
Python 3.10.10 (main, Mar  5 2023, 22:26:53) [GCC 12.2.1 20230201]

OS / Environment

Linux my-x1-yoga 6.1.23-1-lts #1 SMP PREEMPT_DYNAMIC Thu, 06 Apr 2023 10:56:12 +0000 x86_64 GNU/Linux
(Arch Linux)

Additional dependencies

No response

@ioah86 ioah86 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Apr 10, 2023
@DanielNoord DanielNoord added False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Apr 10, 2023
@jacobtylerwalls jacobtylerwalls added Minor 💅 Polishing pylint is always nice Documentation 📗 and removed False Positive 🦟 A message is emitted but nothing is wrong with the code labels Apr 16, 2023
@jacobtylerwalls
Copy link
Member

Thanks for opening the issue. The error should still be raised, as your list comprehension could be a generator instead:

min((i for i in range(len(line)) if line[i] not in whitespaces), default=0)

But the error message isn't showing you that. It's:

  • missing the keyword arg default=0
  • and thus neglects to parenthesize the generator.

Leaving this open to improve the message.

@jacobtylerwalls jacobtylerwalls changed the title consider-using-generator has a false positive for min function with default arguments. consider-using-generator error message ignores default arguments Apr 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation 📗 Minor 💅 Polishing pylint is always nice Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
3 participants