(pat)
Accepts a pytree Pattern Node and returns a set
        of the pattern types which will match first.
Accepts a pytree Pattern Node and returns a set
        of the pattern types which will match first.
Accepts a pytree Pattern Node and returns a set of the pattern types which will match first .
def _get_head_types(pat):
    """ Accepts a pytree Pattern Node and returns a set
        of the pattern types which will match first. """

    if isinstance(pat, (pytree.NodePattern, pytree.LeafPattern)):
        # NodePatters must either have no type and no content
        #   or a type and content -- so they don't get any farther
        # Always return leafs
        if pat.type is None:
            raise _EveryNode
        return set([pat.type])

    if isinstance(pat, pytree.NegatedPattern):
        if pat.content:
            return _get_head_types(pat.content)
        raise _EveryNode # Negated Patterns don't have a type

    if isinstance(pat, pytree.WildcardPattern):
        # Recurse on each node in content
        r = set()
        for p in pat.content:
            for x in p:
                r.update(_get_head_types(x))
        return r

    raise Exception("Oh no! I don't understand pattern %s" %(pat))
def _get_head_types ( pat ) : if isinstance ( pat , ( pytree . NodePattern , pytree . LeafPattern ) ) : # NodePatters must either have no type and no content #   or a type and content -- so they don't get any farther # Always return leafs if pat . type is None : raise _EveryNode return set ( [ pat . type ] ) if isinstance ( pat , pytree . NegatedPattern ) : if pat . content : return _get_head_types ( pat . content ) raise _EveryNode # Negated Patterns don't have a type if isinstance ( pat , pytree . WildcardPattern ) : # Recurse on each node in content r = set ( ) for p in pat . content : for x in p : r . update ( _get_head_types ( x ) ) return r raise Exception ( "Oh no! I don't understand pattern %s" % ( pat ) )