Skip to content

Commit

Permalink
Merge 74b7b39 into 3905173
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivansh-007 committed Jan 24, 2022
2 parents 3905173 + 74b7b39 commit caae8eb
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
`--preview` (#2789)
- Enable Python 3.10+ by default, without any extra need to specify
`--target-version=py310`. (#2758)
- Use parenthesis on method access on number integerals (float and int) (#2799)

### Packaging

Expand Down
8 changes: 8 additions & 0 deletions src/black/linegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ def visit_decorators(self, node: Node) -> Iterator[Line]:
yield from self.line()
yield from self.visit(child)

def visit_power(self, node: Node) -> Iterator[Line]:
for idx, leaf in enumerate(node.children[:-1]):
next_leaf = node.children[idx + 1]
if leaf.type == token.NUMBER and next_leaf.type == syms.trailer:
wrap_in_parentheses(node, leaf)

yield from self.visit_default(node)

def visit_SEMI(self, leaf: Leaf) -> Iterator[Line]:
"""Remove a semicolon and put the other statement on a separate line."""
yield from self.line()
Expand Down
9 changes: 6 additions & 3 deletions tests/data/expression.diff
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
True
False
1
@@ -29,63 +29,96 @@
@@ -29,91 +29,127 @@
~great
+value
-1
Expand Down Expand Up @@ -130,8 +130,11 @@
call(**self.screen_kwargs)
call(b, **self.screen_kwargs)
lukasz.langa.pl
@@ -94,26 +127,29 @@
1.0 .real
call.me(maybe)
-1 .real
-1.0 .real
+(1).real
+(1.0).real
....__class__
list[str]
dict[str, int]
Expand Down
4 changes: 2 additions & 2 deletions tests/data/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ async def f():
call(b, **self.screen_kwargs)
lukasz.langa.pl
call.me(maybe)
1 .real
1.0 .real
(1).real
(1.0).real
....__class__
list[str]
dict[str, int]
Expand Down
9 changes: 6 additions & 3 deletions tests/data/expression_skip_magic_trailing_comma.diff
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
True
False
1
@@ -29,63 +29,84 @@
@@ -29,91 +29,110 @@
~great
+value
-1
Expand Down Expand Up @@ -118,8 +118,11 @@
call(**self.screen_kwargs)
call(b, **self.screen_kwargs)
lukasz.langa.pl
@@ -94,26 +115,24 @@
1.0 .real
call.me(maybe)
-1 .real
-1.0 .real
+(1).real
+(1.0).real
....__class__
list[str]
dict[str, int]
Expand Down
24 changes: 24 additions & 0 deletions tests/data/use_braces_in_int_method_calls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
count = 5 .bit_count()
abs = 10 .__abs__()
is_integer = 10.5 .is_integer()

if 10 .real: ...

for number in range(1, 10):
if number.imag: ...


# output
count = (5).bit_count()
abs = (10).__abs__()
is_integer = (10.5).is_integer()

if (10).real:
...

for number in range(1, 10):
if number.imag:
...



1 change: 1 addition & 0 deletions tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"string_prefixes",
"tricky_unicode_symbols",
"tupleassign",
"use_braces_in_int_method_calls",
]

PY310_CASES: List[str] = [
Expand Down

0 comments on commit caae8eb

Please sign in to comment.