-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
False positive for use-yield-from
for generators yielding from iterators
#9696
Labels
False Positive 🦟
A message is emitted but nothing is wrong with the code
Milestone
Comments
jakelishman
added
the
Needs triage 📥
Just created, needs acknowledgment, triage, and proper labelling
label
Jun 5, 2024
jakelishman
added a commit
to jakelishman/pylint
that referenced
this issue
Jun 6, 2024
If the return value from `yield` is inspected inline, such as by (augmented) assignment, changing the looped `yield` to `yield from` is very likely to change the semantics of the generator, since there is an implicit use of `generator.send`. Closes pylint-dev#9696
Pierre-Sassoulas
added
False Positive 🦟
A message is emitted but nothing is wrong with the code
and removed
Needs triage 📥
Just created, needs acknowledgment, triage, and proper labelling
labels
Jun 6, 2024
Pierre-Sassoulas
pushed a commit
that referenced
this issue
Jun 6, 2024
If the return value from `yield` is inspected inline, such as by (augmented) assignment, changing the looped `yield` to `yield from` is very likely to change the semantics of the generator, since there is an implicit use of `generator.send`. Closes #9696
Pierre-Sassoulas
pushed a commit
that referenced
this issue
Jun 6, 2024
…) (#9701) If the return value from `yield` is inspected inline, such as by (augmented) assignment, changing the looped `yield` to `yield from` is very likely to change the semantics of the generator, since there is an implicit use of `generator.send`. Closes #9696 (cherry picked from commit ea73bae) Co-authored-by: Jake Lishman <[email protected]>
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug description
Within a generator expression, pylint issues
use-yield-from
for constructs such as:When
iterator
is anIterator
and not aGenerator
, it will not have thegenerator
methods (e.g.send
), so applying Pylint's suggestion will modify the type ofmy_generator
fromGenerator[T, S, S]
toGenerator[T, None, None]
(and will generally causeAttributeError
to be raised on calls tosend
).Example file
generator.py
:Configuration
No response
Command used
Pylint output
Expected behavior
In many cases, I suspect that the message is worth the risk of the false positive:
probably should emit the message, but imo neither of my examples in
generator.py
should, maybe unlessiterable
could be inferred to be a compatible type (which it explicitly isn't in my example).Pylint version
OS / Environment
No response
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: