Beispiel #1
0
    def fix_function_overloads(self,
                               stmts: List[Statement]) -> List[Statement]:
        ret: List[Statement] = []
        current_overload: List[OverloadPart] = []
        current_overload_name: Optional[str] = None
        for stmt in stmts:
            if (current_overload_name is not None
                    and isinstance(stmt, (Decorator, FuncDef))
                    and stmt.name == current_overload_name):
                current_overload.append(stmt)
            else:
                if len(current_overload) == 1:
                    ret.append(current_overload[0])
                elif len(current_overload) > 1:
                    ret.append(OverloadedFuncDef(current_overload))

                if isinstance(stmt,
                              Decorator) and not unnamed_function(stmt.name):
                    current_overload = [stmt]
                    current_overload_name = stmt.name
                else:
                    current_overload = []
                    current_overload_name = None
                    ret.append(stmt)

        if len(current_overload) == 1:
            ret.append(current_overload[0])
        elif len(current_overload) > 1:
            ret.append(OverloadedFuncDef(current_overload))
        return ret
Beispiel #2
0
def short_id_from_name(func_name: str, shortname: str,
                       line: Optional[int]) -> str:
    if unnamed_function(func_name):
        assert line is not None
        partial_name = "{}.{}".format(shortname, line)
    else:
        partial_name = shortname
    return partial_name
Beispiel #3
0
def short_id_from_name(func_name: str, shortname: str,
                       line: Optional[int]) -> str:
    if unnamed_function(func_name):
        assert line is not None
        partial_name = f"{shortname}.{line}"
    else:
        partial_name = shortname
    return partial_name
Beispiel #4
0
def get_id_from_name(name: str, fullname: str, line: int) -> str:
    """Create a unique id for a function.

    This creates an id that is unique for any given function definition, so that it can be used as
    a dictionary key. This is usually the fullname of the function, but this is different in that
    it handles the case where the function is named '_', in which case multiple different functions
    could have the same name."""
    if unnamed_function(name):
        return "{}.{}".format(fullname, line)
    else:
        return fullname