def analyze_union_member_access(name: str, typ: UnionType, mx: MemberContext) -> Type: with mx.msg.disable_type_names(): results = [] for subtype in typ.relevant_items(): # Self types should be bound to every individual item of a union. item_mx = mx.copy_modified(self_type=subtype) results.append(_analyze_member_access(name, subtype, item_mx)) return make_simplified_union(results)
def analyze_union_member_access(name: str, typ: UnionType, mx: MemberContext) -> Type: mx.msg.disable_type_names += 1 results = [ _analyze_member_access(name, subtype, mx) for subtype in typ.relevant_items() ] mx.msg.disable_type_names -= 1 return UnionType.make_simplified_union(results)
def _extract_literals(u: UnionType) -> Tuple[Set[Type], List[Type]]: """Given a UnionType, separate out its items into a set of simple literals and a remainder list This is a useful helper to avoid O(n**2) behavior when comparing large unions, which can often result from large enums in contexts where type narrowing removes a small subset of entries. """ lit: Set[Type] = set() rem: List[Type] = [] for i in u.relevant_items(): i = get_proper_type(i) if is_simple_literal(i): lit.add(i) else: rem.append(i) return lit, rem
def analyze_union_member_access(name: str, typ: UnionType, mx: MemberContext) -> Type: mx.msg.disable_type_names += 1 results = [_analyze_member_access(name, subtype, mx) for subtype in typ.relevant_items()] mx.msg.disable_type_names -= 1 return UnionType.make_simplified_union(results)