def get_typed_dict_type( ctx: FunctionContext, handler_arg_type: ProperType, oas_type: oas_model.OASObjectType, ) -> TypedDictType: if isinstance(handler_arg_type, UnionType): td_type_fallback = next( try_getting_instance_fallback(get_proper_type(x)) for x in handler_arg_type.relevant_items()) else: td_type_fallback = try_getting_instance_fallback(handler_arg_type) assert td_type_fallback is not None return TypedDictType( items=OrderedDict({ oas_prop_name: transform_oas_type(oas_prop_type, handler_arg_type, ctx) for oas_prop_name, oas_prop_type in oas_type.properties.items() }), required_keys=oas_type.required, fallback=td_type_fallback, line=td_type_fallback.line, column=td_type_fallback.column, )
def is_enum_overlapping_union(x: ProperType, y: ProperType) -> bool: """Return True if x is an Enum, and y is an Union with at least one Literal from x""" return (isinstance(x, Instance) and x.type.is_enum and isinstance(y, UnionType) and any( isinstance(p, LiteralType) and x.type == p.fallback.type for p in (get_proper_type(z) for z in y.relevant_items())))