def simplify_recursive(typ):
    # type: (AbstractType) -> AbstractType
    """Simplify all components of a type."""
    if isinstance(typ, UnionType):
        return combine_types(typ.items)
    elif isinstance(typ, ClassType):
        simplified = ClassType(typ.name, [simplify_recursive(arg) for arg in typ.args])
        args = simplified.args
        if (simplified.name == 'Dict' and len(args) == 2
                and isinstance(args[0], ClassType) and args[0].name in ('str', 'Text')
                and isinstance(args[1], UnionType) and not is_optional(args[1])):
            # Looks like a potential case for TypedDict, which we don't properly support yet.
            return ClassType('Dict', [args[0], AnyType()])
        return simplified
    elif isinstance(typ, TupleType):
        return TupleType([simplify_recursive(item) for item in typ.items])
    return typ
def simplify_recursive ( typ ) : if isinstance ( typ , UnionType ) : return combine_types ( typ . items ) elif isinstance ( typ , ClassType ) : simplified = ClassType ( typ . name , [ simplify_recursive ( arg ) for arg in typ . args ] ) args = simplified . args if ( simplified . name == 'Dict' and len ( args ) == 2 and isinstance ( args [ 0 ] , ClassType ) and args [ 0 ] . name in ( 'str' , 'Text' ) and isinstance ( args [ 1 ] , UnionType ) and not is_optional ( args [ 1 ] ) ) : return ClassType ( 'Dict' , [ args [ 0 ] , AnyType ( ) ] ) return simplified elif isinstance ( typ , TupleType ) : return TupleType ( [ simplify_recursive ( item ) for item in typ . items ] ) return typ
Simplify all components of a type.