mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:43 +00:00

## Summary Resolves #15997. Ruff used to introduce syntax errors while fixing these cases, but no longer will: ```python {"a": [], **{},} # ^^^^ Removed, leaving two contiguous commas {"a": [], **({})} # ^^^^^ Removed, leaving a stray closing parentheses ``` Previously, the function would take a shortcut if the unpacked dictionary is empty; now, both cases are handled using the same logic introduced in #15394. This change slightly modifies that logic to also remove the first comma following the dictionary, if and only if it is empty. ## Test Plan `cargo nextest run` and `cargo insta test`.
108 lines
1.5 KiB
Python
108 lines
1.5 KiB
Python
{"foo": 1, **{"bar": 1}} # PIE800
|
|
|
|
{**{"bar": 10}, "a": "b"} # PIE800
|
|
|
|
foo({**foo, **{"bar": True}}) # PIE800
|
|
|
|
{**foo, **{"bar": 10}} # PIE800
|
|
|
|
{ # PIE800
|
|
"a": "b",
|
|
# Preserve
|
|
**{
|
|
# all
|
|
"bar": 10, # the
|
|
# comments
|
|
},
|
|
}
|
|
|
|
{**foo, **buzz, **{bar: 10}} # PIE800
|
|
|
|
# https://github.com/astral-sh/ruff/issues/15366
|
|
{
|
|
"data": [],
|
|
**({"count": 1 if include_count else {}}),
|
|
}
|
|
|
|
{
|
|
"data": [],
|
|
**( # Comment
|
|
{ # Comment
|
|
"count": 1 if include_count else {}}),
|
|
}
|
|
|
|
{
|
|
"data": [],
|
|
**(
|
|
{
|
|
"count": (a := 1),}),
|
|
}
|
|
|
|
{
|
|
"data": [],
|
|
**(
|
|
{
|
|
"count": (a := 1)
|
|
}
|
|
)
|
|
,
|
|
}
|
|
|
|
{
|
|
"data": [],
|
|
**(
|
|
{
|
|
"count": (a := 1), # Comment
|
|
} # Comment
|
|
) # Comment
|
|
,
|
|
}
|
|
|
|
({
|
|
"data": [],
|
|
**( # Comment
|
|
( # Comment
|
|
{ # Comment
|
|
"count": (a := 1), # Comment
|
|
} # Comment
|
|
)
|
|
) # Comment
|
|
,
|
|
})
|
|
|
|
{
|
|
"data": [],
|
|
** # Foo
|
|
( # Comment
|
|
{ "a": b,
|
|
# Comment
|
|
}
|
|
) ,
|
|
c: 9,
|
|
}
|
|
|
|
|
|
# https://github.com/astral-sh/ruff/issues/15997
|
|
{"a": [], **{},}
|
|
{"a": [], **({}),}
|
|
|
|
{"a": [], **{}, 6: 3}
|
|
{"a": [], **({}), 6: 3}
|
|
|
|
{"a": [], **{
|
|
# Comment
|
|
}, 6: 3}
|
|
{"a": [], **({
|
|
# Comment
|
|
}), 6: 3}
|
|
|
|
|
|
{**foo, "bar": True } # OK
|
|
|
|
{"foo": 1, "buzz": {"bar": 1}} # OK
|
|
|
|
{**foo, "bar": True } # OK
|
|
|
|
Table.objects.filter(inst=inst, **{f"foo__{bar}__exists": True}) # OK
|
|
|
|
buzz = {**foo, "bar": { 1: 2 }} # OK
|