-
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
Single-line match-cases with Ellipsis (...
) as body
#11676
Comments
I'm open to this but I don't think it should be specific to match cases. Instead, it is a more general question if |
What other cases would there be? Any statement ending with a First brainstorm: if expr: ...
elif expr: ...
else: ...
while expr: ...
for val in expr: ...
class Foo: ...
def foo(): ...
async def foo(): ...
match expr: ...
case pattern: ...
try: ...
except: ...
finally: ...
with expr as val: ...
async with expr as val: ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the great work on ruff!
Not sure if this a bug, probably rather a feature request. Curious to hear what you think about this:
I work with complexly nested data and sometimes I want to extract a value from potentially different parts of the data, depending on the structure of the data. I realized that you can quite nicely use "structural pattern matching" for that, e.g. here's a simple example:
I wrote the single-line case statements similar to how you can write single-line function signatures for e.g. Protocols (e.g. refer to #10026). However, ruff will always reformat them to:
I was wondering if case-statements should also allowed to be single-line if the body is an Ellipsis
...
for consistency?The text was updated successfully, but these errors were encountered: