diff --git a/yapf/yapflib/object_state.py b/yapf/yapflib/object_state.py index 41b58aeff..124ae6566 100644 --- a/yapf/yapflib/object_state.py +++ b/yapf/yapflib/object_state.py @@ -24,7 +24,6 @@ from yapf.yapflib import format_token from yapf.yapflib import py3compat -from yapf.yapflib import pytree_utils from yapf.yapflib import style @@ -90,6 +89,9 @@ class ParameterListState(object): Attributes: opening_bracket: The opening bracket of the parameter list. + closing_bracket: The closing bracket of the parameter list. + has_typed_return: True if the function definition has a typed return. + has_default_values: True if the parameters have default values. has_split_before_first_param: Whether there is a newline before the first parameter. opening_column: The position of the opening parameter before a newline. @@ -120,6 +122,7 @@ def has_default_values(self): @py3compat.lru_cache() def LastParamFitsOnLine(self, indent): + """Return true if the last parameter fits on a single line.""" if not self.has_typed_return: return False last_param = self.parameters[-1].first_token @@ -162,6 +165,7 @@ class Parameter(object): Attributes: first_token: (format_token.FormatToken) First token of parameter. last_token: (format_token.FormatToken) Last token of parameter. + has_default_value: (boolean) True if the parameter has a default value """ def __init__(self, first_token, last_token): @@ -171,6 +175,7 @@ def __init__(self, first_token, last_token): @property @py3compat.lru_cache() def has_default_value(self): + """Returns true if the parameter has a default value.""" tok = self.first_token while tok != self.last_token: if format_token.Subtype.DEFAULT_OR_NAMED_ASSIGN in tok.subtypes: diff --git a/yapf/yapflib/pytree_unwrapper.py b/yapf/yapflib/pytree_unwrapper.py index ca6784dbb..f4d9cbafc 100644 --- a/yapf/yapflib/pytree_unwrapper.py +++ b/yapf/yapflib/pytree_unwrapper.py @@ -32,9 +32,9 @@ from lib2to3.pgen2 import token as grammar_token from yapf.yapflib import format_token +from yapf.yapflib import object_state from yapf.yapflib import pytree_utils from yapf.yapflib import pytree_visitor -from yapf.yapflib import object_state from yapf.yapflib import split_penalty from yapf.yapflib import style from yapf.yapflib import unwrapped_line diff --git a/yapf/yapflib/subtype_assigner.py b/yapf/yapflib/subtype_assigner.py index 585f265f2..0fa2d9663 100644 --- a/yapf/yapflib/subtype_assigner.py +++ b/yapf/yapflib/subtype_assigner.py @@ -299,7 +299,7 @@ def Visit_typedargslist(self, node): # pylint: disable=invalid-name _SetArgListSubtype(node, format_token.Subtype.DEFAULT_OR_NAMED_ASSIGN, format_token.Subtype.DEFAULT_OR_NAMED_ASSIGN_ARG_LIST) tname = False - if not len(node.children): + if not node.children: return _AppendFirstLeafTokenSubtype(node.children[0], diff --git a/yapftests/subtype_assigner_test.py b/yapftests/subtype_assigner_test.py index 2a74a83ec..b42b8cfab 100644 --- a/yapftests/subtype_assigner_test.py +++ b/yapftests/subtype_assigner_test.py @@ -43,7 +43,7 @@ def _CheckFormatTokenSubtypes(self, uwlines, list_of_expected): self.assertEqual(list_of_expected, actual) def testFuncDefDefaultAssign(self): - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name code = textwrap.dedent(r""" def foo(a=37, *b, **c): return -x[:42]