MCPcopy Index your code
hub / github.com/python/mypy / read_type

Function read_type

mypy/nativeparse.py:832–968  ·  view source on GitHub ↗
(state: State, data: ReadBuffer)

Source from the content-addressed store, hash-verified

830
831
832def read_type(state: State, data: ReadBuffer) -> Type:
833 tag = read_tag(data)
834 if tag == types.UNBOUND_TYPE:
835 name = read_str(data)
836 expect_tag(data, LIST_GEN)
837 n = read_int_bare(data)
838 args = tuple(read_type(state, data) for i in range(n))
839 empty_tuple_index = read_bool(data)
840 t = read_tag(data)
841 if t == LITERAL_NONE:
842 original_str_expr = None
843 elif t == LITERAL_STR:
844 original_str_expr = read_str_bare(data)
845 else:
846 assert False, f"Unexpected tag for original_str_expr: {t}"
847 t = read_tag(data)
848 if t == LITERAL_NONE:
849 original_str_fallback = None
850 elif t == LITERAL_STR:
851 original_str_fallback = read_str_bare(data)
852 else:
853 assert False, f"Unexpected tag for original_str_fallback: {t}"
854 unbound = UnboundType(
855 name,
856 args,
857 empty_tuple_index=empty_tuple_index,
858 original_str_expr=original_str_expr,
859 original_str_fallback=original_str_fallback,
860 )
861 read_loc(data, unbound)
862 expect_end_tag(data)
863 return unbound
864 elif tag == types.UNION_TYPE:
865 expect_tag(data, LIST_GEN)
866 n = read_int_bare(data)
867 items = [read_type(state, data) for i in range(n)]
868 uses_pep604_syntax = read_bool(data)
869 t = read_tag(data)
870 if t == LITERAL_NONE:
871 original_str_expr = None
872 elif t == LITERAL_STR:
873 original_str_expr = read_str_bare(data)
874 else:
875 assert False, f"Unexpected tag for original_str_expr: {t}"
876 t = read_tag(data)
877 if t == LITERAL_NONE:
878 original_str_fallback = None
879 elif t == LITERAL_STR:
880 original_str_fallback = read_str_bare(data)
881 else:
882 assert False, f"Unexpected tag for original_str_fallback: {t}"
883 union = UnionType(items, uses_pep604_syntax=uses_pep604_syntax)
884 union.original_str_expr = original_str_expr
885 union.original_str_fallback = original_str_fallback
886 union.is_evaluated = read_bool(data)
887 read_loc(data, union)
888 expect_end_tag(data)
889 return union

Callers 6

read_statementFunction · 0.70
read_parametersFunction · 0.70
read_type_paramsFunction · 0.70
read_func_defFunction · 0.70
read_type_alias_stmtFunction · 0.70
read_call_typeFunction · 0.70

Calls 15

read_strFunction · 0.90
UnboundTypeClass · 0.90
UnionTypeClass · 0.90
TypeListClass · 0.90
TupleTypeClass · 0.90
read_str_optFunction · 0.90
TypedDictTypeClass · 0.90
EllipsisTypeClass · 0.90
read_intFunction · 0.90
RawExpressionTypeClass · 0.90
UnpackTypeClass · 0.90
expect_tagFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…