Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@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
if not self.parameters:
return True
last_param = self.parameters[-1].first_token
last_token = self.opening_bracket.matching_bracket
while not last_token.is_comment and last_token.next_token:
last_token = last_token.next_token
total_length = last_token.total_length
total_length -= last_param.total_length - len(last_param.value)
return total_length + indent <= style.Get('COLUMN_LIMIT')
@py3compat.lru_cache()
def is_pseudo_paren(self):
return hasattr(self.node, 'is_pseudo') and self.node.is_pseudo
@py3compat.lru_cache()
def is_name(self):
return self.node.type == token.NAME and not self.is_keyword
@py3compat.lru_cache()
def is_arithmetic_op(self):
"""Token is an arithmetic operator."""
return self.is_a_expr_op or self.is_m_expr_op
@py3compat.lru_cache()
def is_keyword(self):
return keyword.iskeyword(self.value)
@py3compat.lru_cache()
def node_split_penalty(self):
"""Split penalty attached to the pytree node of this token."""
return pytree_utils.GetNodeAnnotation(
self.node, pytree_utils.Annotation.SPLIT_PENALTY, default=0)
@py3compat.lru_cache()
def name(self):
"""A string representation of the node's name."""
return pytree_utils.NodeName(self.node)
@py3compat.lru_cache()
def is_simple_expr(self):
"""Token is an operator in a simple expression."""
return Subtype.SIMPLE_EXPRESSION in self.subtypes
@py3compat.lru_cache()
def subtypes(self):
"""Extra type information for directing formatting."""
value = pytree_utils.GetNodeAnnotation(self.node,
pytree_utils.Annotation.SUBTYPE)
return [Subtype.NONE] if value is None else value
@py3compat.lru_cache()
def has_default_values(self):
return any(param.has_default_value for param in self.parameters)