-
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
B901: Misses yield
sub-expresisons
#14453
Comments
hmm, this isn't valid syntax: >>> from typing import *
>>> from pathlib import Path
>>> def get_file_paths(file_types: Iterable[str] | None = None) -> Iterable[Path]:
... dir_path = Path(".")
... if file_types is None:
... return dir_path.glob("*")
...
... for file_type in file_types:
... (yield a for a in dir_path.glob(f"*.{file_type}"))
...
File "<python-input-2>", line 7
(yield a for a in dir_path.glob(f"*.{file_type}"))
^^^
SyntaxError: invalid syntax |
hmm, I only tested with our parser. nested yield expressions are definitely valid :) |
Okay, found one
|
Here's another function that is a generator function with a def f():
x = yield
print(x)
return 42 This is a generator function that you can >>> def f():
... x = yield
... print(x)
... return 42
...
>>> y = f()
>>> next(y)
>>> y.send('foo')
foo
Traceback (most recent call last):
File "<python-input-13>", line 1, in <module>
y.send('foo')
~~~~~~^^^^^^^
StopIteration: 42
|
Hi @MichaReiser @AlexWaygood can I help you fix this issue ? |
Sure. You can find the code for this rule in this file |
Thanks @MichaReiser excited to work on this ! |
A very contrived example but
B901
misses yield expressions where they're not the expression of aExprStmt
.Note: we should make sure that we don't traverse into any lambda expressions...
The text was updated successfully, but these errors were encountered: