mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:39:12 +00:00
fix: Don't omit optional parentheses for subscripts (#7380)
This commit is contained in:
parent
04183b0299
commit
a65efcf459
6 changed files with 53 additions and 50 deletions
|
@ -275,23 +275,7 @@ last_call()
|
|||
flags & ~select.EPOLLIN and waiters.write_task is not None
|
||||
lambda arg: None
|
||||
lambda a=True: a
|
||||
@@ -39,10 +39,11 @@
|
||||
lambda a, b, c=True, *, d=(1 << v2), e="str": a
|
||||
lambda a, b, c=True, *vararg, d=(v1 << 2), e="str", **kwargs: a + b
|
||||
manylambdas = lambda x=lambda y=lambda z=1: z: y(): x()
|
||||
-foo = lambda port_id, ignore_missing: {
|
||||
- "port1": port1_resource,
|
||||
- "port2": port2_resource,
|
||||
-}[port_id]
|
||||
+foo = (
|
||||
+ lambda port_id, ignore_missing: {"port1": port1_resource, "port2": port2_resource}[
|
||||
+ port_id
|
||||
+ ]
|
||||
+)
|
||||
1 if True else 2
|
||||
str or None if True else str or bytes or None
|
||||
(str or None) if True else (str or bytes or None)
|
||||
@@ -115,7 +116,7 @@
|
||||
@@ -115,7 +115,7 @@
|
||||
arg,
|
||||
another,
|
||||
kwarg="hey",
|
||||
|
@ -346,11 +330,10 @@ lambda a, b, c=True: a
|
|||
lambda a, b, c=True, *, d=(1 << v2), e="str": a
|
||||
lambda a, b, c=True, *vararg, d=(v1 << 2), e="str", **kwargs: a + b
|
||||
manylambdas = lambda x=lambda y=lambda z=1: z: y(): x()
|
||||
foo = (
|
||||
lambda port_id, ignore_missing: {"port1": port1_resource, "port2": port2_resource}[
|
||||
port_id
|
||||
]
|
||||
)
|
||||
foo = lambda port_id, ignore_missing: {
|
||||
"port1": port1_resource,
|
||||
"port2": port2_resource,
|
||||
}[port_id]
|
||||
1 if True else 2
|
||||
str or None if True else str or bytes or None
|
||||
(str or None) if True else (str or bytes or None)
|
||||
|
|
|
@ -324,13 +324,13 @@ ct_match = (
|
|||
aaaaaaaaaaact_id == self.get_content_type(obj=rel_obj, using=instance._state.db)[id]
|
||||
)
|
||||
|
||||
ct_match = {
|
||||
aaaaaaaaaaaaaaaa
|
||||
} == self.get_content_type(obj=rel_obj, using=instance._state.db)[id]
|
||||
ct_match = {aaaaaaaaaaaaaaaa} == self.get_content_type(
|
||||
obj=rel_obj, using=instance._state.db
|
||||
)[id]
|
||||
|
||||
ct_match = (
|
||||
aaaaaaaaaaaaaaaa
|
||||
) == self.get_content_type(obj=rel_obj, using=instance._state.db)[id]
|
||||
ct_match = (aaaaaaaaaaaaaaaa) == self.get_content_type(
|
||||
obj=rel_obj, using=instance._state.db
|
||||
)[id]
|
||||
|
||||
# Subscripts expressions with trailing attributes.
|
||||
|
||||
|
|
|
@ -97,6 +97,13 @@ f = "f"[:,]
|
|||
g1 = "g"[(1):(2)]
|
||||
g2 = "g"[(1):(2):(3)]
|
||||
|
||||
# Don't omit optional parentheses for subscripts
|
||||
# https://github.com/astral-sh/ruff/issues/7319
|
||||
def f():
|
||||
return (
|
||||
package_version is not None
|
||||
and package_version.split(".")[:2] == package_info.version.split(".")[:2]
|
||||
)
|
||||
```
|
||||
|
||||
## Output
|
||||
|
@ -191,6 +198,15 @@ f = "f"[:,]
|
|||
# Regression test for https://github.com/astral-sh/ruff/issues/5733
|
||||
g1 = "g"[(1):(2)]
|
||||
g2 = "g"[(1):(2):(3)]
|
||||
|
||||
|
||||
# Don't omit optional parentheses for subscripts
|
||||
# https://github.com/astral-sh/ruff/issues/7319
|
||||
def f():
|
||||
return (
|
||||
package_version is not None
|
||||
and package_version.split(".")[:2] == package_info.version.split(".")[:2]
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue