You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
classUser(BaseModel):
global_name: str# ...classMember(BaseModel):
nickname: Optional[str]
user: User# ...name: strmatchmember:
caseMember(nickname=str(name)): ...
caseMember(user=User(global_name=str(name))): ...
# Now `name` is bound, depending on which structure first "resolved". If the member had# a nickname defined, we prefer using that. Otherwise we use the global_name.
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'm open to this but I don't think it should be specific to match cases. Instead, it is a more general question if ... bodies should be collapsed in compound statements.
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: