Properle space complex expressions in default values of typed arguments
Fixes #60
This commit is contained in:
parent
7bd6f3cb2f
commit
cf6f577928
@ -311,6 +311,9 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
|
|||||||
* automatic detection of deprecated Python 2 forms of print statements
|
* automatic detection of deprecated Python 2 forms of print statements
|
||||||
and exec statements in the formatted file (#49)
|
and exec statements in the formatted file (#49)
|
||||||
|
|
||||||
|
* use proper spaces for complex expressions in default values of typed
|
||||||
|
function arguments (#60)
|
||||||
|
|
||||||
* only return exit code 1 when --check is used (#50)
|
* only return exit code 1 when --check is used (#50)
|
||||||
|
|
||||||
* don't remove single trailing commas from square bracket indexing
|
* don't remove single trailing commas from square bracket indexing
|
||||||
|
23
black.py
23
black.py
@ -419,7 +419,7 @@ def any_open_brackets(self) -> bool:
|
|||||||
"""Returns True if there is an yet unmatched open bracket on the line."""
|
"""Returns True if there is an yet unmatched open bracket on the line."""
|
||||||
return bool(self.bracket_match)
|
return bool(self.bracket_match)
|
||||||
|
|
||||||
def max_priority(self, exclude: Iterable[LeafID] =()) -> int:
|
def max_priority(self, exclude: Iterable[LeafID] = ()) -> int:
|
||||||
"""Returns the highest priority of a delimiter found on the line.
|
"""Returns the highest priority of a delimiter found on the line.
|
||||||
|
|
||||||
Values are consistent with what `is_delimiter()` returns.
|
Values are consistent with what `is_delimiter()` returns.
|
||||||
@ -885,14 +885,17 @@ def whitespace(leaf: Leaf) -> str: # noqa C901
|
|||||||
return SPACE if prevp.type == token.COMMA else NO
|
return SPACE if prevp.type == token.COMMA else NO
|
||||||
|
|
||||||
if prevp.type == token.EQUAL:
|
if prevp.type == token.EQUAL:
|
||||||
if prevp.parent and prevp.parent.type in {
|
if prevp.parent:
|
||||||
syms.arglist,
|
if prevp.parent.type in {
|
||||||
syms.argument,
|
syms.arglist, syms.argument, syms.parameters, syms.varargslist
|
||||||
syms.parameters,
|
}:
|
||||||
syms.typedargslist,
|
return NO
|
||||||
syms.varargslist,
|
|
||||||
}:
|
elif prevp.parent.type == syms.typedargslist:
|
||||||
return NO
|
# A bit hacky: if the equal sign has whitespace, it means we
|
||||||
|
# previously found it's a typed argument. So, we're using
|
||||||
|
# that, too.
|
||||||
|
return prevp.prefix
|
||||||
|
|
||||||
elif prevp.type == token.DOUBLESTAR:
|
elif prevp.type == token.DOUBLESTAR:
|
||||||
if prevp.parent and prevp.parent.type in {
|
if prevp.parent and prevp.parent.type in {
|
||||||
@ -938,7 +941,7 @@ def whitespace(leaf: Leaf) -> str: # noqa C901
|
|||||||
if not prev or prev.type != token.COMMA:
|
if not prev or prev.type != token.COMMA:
|
||||||
return NO
|
return NO
|
||||||
|
|
||||||
if p.type == syms.varargslist:
|
elif p.type == syms.varargslist:
|
||||||
# lambdas
|
# lambdas
|
||||||
if t == token.RPAR:
|
if t == token.RPAR:
|
||||||
return NO
|
return NO
|
||||||
|
@ -31,6 +31,7 @@ def function_signature_stress_test(number:int,no_annotation=None,text:str="defau
|
|||||||
def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r''):
|
def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r''):
|
||||||
offset = attr.ib(default=attr.Factory( lambda: _r.uniform(10000, 200000)))
|
offset = attr.ib(default=attr.Factory( lambda: _r.uniform(10000, 200000)))
|
||||||
assert task._cancel_stack[:len(old_stack)] == old_stack
|
assert task._cancel_stack[:len(old_stack)] == old_stack
|
||||||
|
def spaces_types(a: int = 1, b: tuple = (), c: list = [], d: dict = {}, e: bool = True, f: int = -1, g: int = 1 if False else 2, h: str = "", i: str = r''): ...
|
||||||
def spaces2(result= _core.Value(None)):
|
def spaces2(result= _core.Value(None)):
|
||||||
...
|
...
|
||||||
def example(session):
|
def example(session):
|
||||||
@ -123,6 +124,20 @@ def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r''
|
|||||||
assert task._cancel_stack[:len(old_stack)] == old_stack
|
assert task._cancel_stack[:len(old_stack)] == old_stack
|
||||||
|
|
||||||
|
|
||||||
|
def spaces_types(
|
||||||
|
a: int = 1,
|
||||||
|
b: tuple = (),
|
||||||
|
c: list = [],
|
||||||
|
d: dict = {},
|
||||||
|
e: bool = True,
|
||||||
|
f: int = -1,
|
||||||
|
g: int = 1 if False else 2,
|
||||||
|
h: str = "",
|
||||||
|
i: str = r'',
|
||||||
|
):
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
def spaces2(result=_core.Value(None)):
|
def spaces2(result=_core.Value(None)):
|
||||||
...
|
...
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user