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

Method anal_type

mypy/semanal.py:7807–7867  ·  view source on GitHub ↗

Semantically analyze a type. Args: typ: Type to analyze (if already analyzed, this is a no-op) allow_placeholder: If True, may return PlaceholderType if encountering an incomplete definition Return None only if some part of the type couldn't

(
        self,
        typ: Type,
        *,
        tvar_scope: TypeVarLikeScope | None = None,
        allow_tuple_literal: bool = False,
        allow_unbound_tvars: bool = False,
        allow_placeholder: bool = False,
        allow_typed_dict_special_forms: bool = False,
        allow_final: bool = False,
        allow_param_spec_literals: bool = False,
        allow_unpack: bool = False,
        report_invalid_types: bool = True,
        prohibit_self_type: str | None = None,
        prohibit_special_class_field_types: str | None = None,
        allow_type_any: bool = False,
    )

Source from the content-addressed store, hash-verified

7805 )
7806
7807 def anal_type(
7808 self,
7809 typ: Type,
7810 *,
7811 tvar_scope: TypeVarLikeScope | None = None,
7812 allow_tuple_literal: bool = False,
7813 allow_unbound_tvars: bool = False,
7814 allow_placeholder: bool = False,
7815 allow_typed_dict_special_forms: bool = False,
7816 allow_final: bool = False,
7817 allow_param_spec_literals: bool = False,
7818 allow_unpack: bool = False,
7819 report_invalid_types: bool = True,
7820 prohibit_self_type: str | None = None,
7821 prohibit_special_class_field_types: str | None = None,
7822 allow_type_any: bool = False,
7823 ) -> Type | None:
7824 """Semantically analyze a type.
7825
7826 Args:
7827 typ: Type to analyze (if already analyzed, this is a no-op)
7828 allow_placeholder: If True, may return PlaceholderType if
7829 encountering an incomplete definition
7830
7831 Return None only if some part of the type couldn't be bound *and* it
7832 referred to an incomplete namespace or definition. In this case also
7833 defer as needed. During a final iteration this won't return None;
7834 instead report an error if the type can't be analyzed and return
7835 AnyType.
7836
7837 In case of other errors, report an error message and return AnyType.
7838
7839 NOTE: The caller shouldn't defer even if this returns None or a
7840 placeholder type.
7841 """
7842 has_self_type = find_self_type(
7843 typ, lambda name: self.lookup_qualified(name, typ, suppress_errors=True)
7844 )
7845 if has_self_type and self.type and prohibit_self_type is None:
7846 self.setup_self_type()
7847 a = self.type_analyzer(
7848 tvar_scope=tvar_scope,
7849 allow_unbound_tvars=allow_unbound_tvars,
7850 allow_tuple_literal=allow_tuple_literal,
7851 allow_placeholder=allow_placeholder,
7852 allow_typed_dict_special_forms=allow_typed_dict_special_forms,
7853 allow_final=allow_final,
7854 allow_param_spec_literals=allow_param_spec_literals,
7855 allow_unpack=allow_unpack,
7856 report_invalid_types=report_invalid_types,
7857 prohibit_self_type=prohibit_self_type,
7858 prohibit_special_class_field_types=prohibit_special_class_field_types,
7859 allow_type_any=allow_type_any,
7860 )
7861 tag = self.track_incomplete_refs()
7862 typ = typ.accept(a)
7863 if self.found_incomplete_ref(tag):
7864 # Something could not be bound yet.

Callers 14

analyze_type_paramMethod · 0.95
analyze_value_typesMethod · 0.95
check_classvarMethod · 0.95
visit_for_stmtMethod · 0.95
visit_with_stmtMethod · 0.95
visit_cast_exprMethod · 0.95
visit_type_form_exprMethod · 0.95

Calls 8

lookup_qualifiedMethod · 0.95
setup_self_typeMethod · 0.95
type_analyzerMethod · 0.95
track_incomplete_refsMethod · 0.95
found_incomplete_refMethod · 0.95
add_type_alias_depsMethod · 0.95
find_self_typeFunction · 0.90
acceptMethod · 0.45

Tested by

no test coverage detected