MCPcopy
hub / github.com/psf/black / is_vararg

Function is_vararg

src/black/nodes.py:790–810  ·  view source on GitHub ↗

Return True if `leaf` is a star or double star in a vararg or kwarg. If `within` includes VARARGS_PARENTS, this applies to function signatures. If `within` includes UNPACKING_PARENTS, it applies to right hand-side extended iterable unpacking (PEP 3132) and additional unpacking gener

(leaf: Leaf, within: set[NodeType])

Source from the content-addressed store, hash-verified

788
789
790def is_vararg(leaf: Leaf, within: set[NodeType]) -> bool:
791 """Return True if `leaf` is a star or double star in a vararg or kwarg.
792
793 If `within` includes VARARGS_PARENTS, this applies to function signatures.
794 If `within` includes UNPACKING_PARENTS, it applies to right hand-side
795 extended iterable unpacking (PEP 3132) and additional unpacking
796 generalizations (PEP 448).
797 """
798 if leaf.type not in VARARGS_SPECIALS or not leaf.parent:
799 return False
800
801 p = leaf.parent
802 if p.type == syms.star_expr:
803 # Star expressions are also used as assignment targets in extended
804 # iterable unpacking (PEP 3132). See what its parent is instead.
805 if not p.parent:
806 return False
807
808 p = p.parent
809
810 return p.type in within
811
812
813def is_fstring(node: Node) -> bool:

Callers 3

_can_add_trailing_commaFunction · 0.90
whitespaceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected