Bool expression comment placement (#7269)

This commit is contained in:
Micha Reiser 2023-09-12 08:39:57 +02:00 committed by GitHub
parent c21b960fc7
commit 1e6df19a35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 776 additions and 145 deletions

View file

@ -326,6 +326,14 @@ rowuses = [(1 << j) | # column ordinal
(1 << (n + 2*n-1 + i+j)) # NE-SW ordinal
for j in rangen]
rowuses = [((1 << j) # column ordinal
)|
(
# comment
(1 << (n + i-j + n-1))) | # NW-SE ordinal
(1 << (n + 2*n-1 + i+j)) # NE-SW ordinal
for j in rangen]
skip_bytes = (
header.timecnt * 5 # Transition times and types
+ header.typecnt * 6 # Local time type records
@ -334,6 +342,59 @@ skip_bytes = (
+ header.isstdcnt # Standard/wall indicators
+ header.isutcnt # UT/local indicators
)
if (
(1 + 2) # test
or (3 + 4) # other
or (4 + 5) # more
):
pass
if (
(1 and 2) # test
+ (3 and 4) # other
+ (4 and 5) # more
):
pass
if (
(1 + 2) # test
< (3 + 4) # other
> (4 + 5) # more
):
pass
z = (
a
+
# a: extracts this comment
(
# b: and this comment
(
# c: formats it as part of the expression
x and y
)
)
)
z = (
(
(
x and y
# a: formats it as part of the expression
)
# b: extracts this comment
)
# c: and this comment
+ a
)
```
## Output
@ -565,19 +626,15 @@ if [
...
if (
[
fffffffffffffffff,
gggggggggggggggggggg,
hhhhhhhhhhhhhhhhhhhhh,
iiiiiiiiiiiiiiii,
jjjjjjjjjjjjj,
]
&
(
# comment
a + b
)
if [
fffffffffffffffff,
gggggggggggggggggggg,
hhhhhhhhhhhhhhhhhhhhh,
iiiiiiiiiiiiiiii,
jjjjjjjjjjjjj,
] & (
# comment
a + b
):
...
@ -706,8 +763,7 @@ expected_content = (
</sitemap>
</sitemapindex>
"""
%
(
% (
# Needs parentheses
self.base_url
)
@ -715,14 +771,21 @@ expected_content = (
rowuses = [
(
1 << j # column ordinal
)
(1 << j) # column ordinal
| (1 << (n + i - j + n - 1)) # NW-SE ordinal
| (1 << (n + 2 * n - 1 + i + j)) # NE-SW ordinal
for j in rangen
]
rowuses = [
(1 << j) # column ordinal
|
# comment
(1 << (n + i - j + n - 1)) # NW-SE ordinal
| (1 << (n + 2 * n - 1 + i + j)) # NE-SW ordinal
for j in rangen
]
skip_bytes = (
header.timecnt * 5 # Transition times and types
+ header.typecnt * 6 # Local time type records
@ -731,6 +794,51 @@ skip_bytes = (
+ header.isstdcnt # Standard/wall indicators
+ header.isutcnt # UT/local indicators
)
if (
(1 + 2) # test
or (3 + 4) # other
or (4 + 5) # more
):
pass
if (
(1 and 2) # test
+ (3 and 4) # other
+ (4 and 5) # more
):
pass
if (
(1 + 2) # test
< (3 + 4) # other
> (4 + 5) # more
):
pass
z = (
a
+
# a: extracts this comment
# b: and this comment
(
# c: formats it as part of the expression
x and y
)
)
z = (
(
x and y
# a: formats it as part of the expression
)
# b: extracts this comment
# c: and this comment
+ a
)
```

View file

@ -108,6 +108,89 @@ def test():
and {k.lower(): v for k, v in self.items()}
== {k.lower(): v for k, v in other.items()}
)
if "_continue" in request.POST or (
# Redirecting after "Save as new".
"_saveasnew" in request.POST
and self.save_as_continue
and self.has_change_permission(request, obj)
):
pass
if True:
if False:
if True:
if (
self.validate_max
and self.total_form_count() - len(self.deleted_forms) > self.max_num
) or self.management_form.cleaned_data[
TOTAL_FORM_COUNT
] > self.absolute_max:
pass
if True:
if (
reference_field_name is None
or
# Unspecified to_field(s).
to_fields is None
or
# Reference to primary key.
(
None in to_fields
and (reference_field is None or reference_field.primary_key)
)
or
# Reference to field.
reference_field_name in to_fields
):
pass
field = opts.get_field(name)
if (
field.is_relation
and
# Generic foreign keys OR reverse relations
((field.many_to_one and not field.related_model) or field.one_to_many)
):
pass
if True:
return (
filtered.exists()
and
# It may happen that the object is deleted from the DB right after
# this check, causing the subsequent UPDATE to return zero matching
# rows. The same result can occur in some rare cases when the
# database returns zero despite the UPDATE being executed
# successfully (a row is matched and updated). In order to
# distinguish these two cases, the object's existence in the
# database is again checked for if the UPDATE query returns 0.
(filtered._update(values) > 0 or filtered.exists())
)
if (self._proc is not None
# has the child process finished?
and self._returncode is None
# the child process has finished, but the
# transport hasn't been notified yet?
and self._proc.poll() is None):
pass
if (self._proc
# has the child process finished?
* self._returncode
# the child process has finished, but the
# transport hasn't been notified yet?
+ self._proc.poll()):
pass
```
## Output
@ -234,6 +317,89 @@ def test():
return isinstance(other, Mapping) and {k.lower(): v for k, v in self.items()} == {
k.lower(): v for k, v in other.items()
}
if "_continue" in request.POST or (
# Redirecting after "Save as new".
"_saveasnew" in request.POST
and self.save_as_continue
and self.has_change_permission(request, obj)
):
pass
if True:
if False:
if True:
if (
self.validate_max
and self.total_form_count() - len(self.deleted_forms) > self.max_num
) or self.management_form.cleaned_data[
TOTAL_FORM_COUNT
] > self.absolute_max:
pass
if True:
if (
reference_field_name is None
or
# Unspecified to_field(s).
to_fields is None
or
# Reference to primary key.
(None in to_fields and (reference_field is None or reference_field.primary_key))
or
# Reference to field.
reference_field_name in to_fields
):
pass
field = opts.get_field(name)
if (
field.is_relation
and
# Generic foreign keys OR reverse relations
((field.many_to_one and not field.related_model) or field.one_to_many)
):
pass
if True:
return (
filtered.exists()
and
# It may happen that the object is deleted from the DB right after
# this check, causing the subsequent UPDATE to return zero matching
# rows. The same result can occur in some rare cases when the
# database returns zero despite the UPDATE being executed
# successfully (a row is matched and updated). In order to
# distinguish these two cases, the object's existence in the
# database is again checked for if the UPDATE query returns 0.
(filtered._update(values) > 0 or filtered.exists())
)
if (
self._proc is not None
# has the child process finished?
and self._returncode is None
# the child process has finished, but the
# transport hasn't been notified yet?
and self._proc.poll() is None
):
pass
if (
self._proc
# has the child process finished?
* self._returncode
# the child process has finished, but the
# transport hasn't been notified yet?
+ self._proc.poll()
):
pass
```

View file

@ -339,13 +339,13 @@ ct_match = (
== 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
# comments

View file

@ -90,8 +90,7 @@ a = (
+ b
+ c
+ d
+
( # Hello
+ ( # Hello
e + f + g
)
)