Class | MemberContext |
Information and objects needed to type check attribute access. |
Function | add_class_tvars |
Instantiate type variables during analyze_class_attribute_access, e.g T and Q in the following: |
Function | analyze_class_attribute_access |
Analyze access to an attribute on a class object. |
Function | analyze_decorator_or_funcbase_access |
Analyzes the type behind method access. |
Function | analyze_descriptor_access |
Type check descriptor access. |
Function | analyze_enum_class_attribute_access |
Undocumented |
Function | analyze_instance_member_access |
Undocumented |
Function | analyze_member_access |
Return the type of attribute 'name' of 'typ'. |
Function | analyze_member_var_access |
Analyse attribute access that does not target a method. |
Function | analyze_none_member_access |
Undocumented |
Function | analyze_type_callable_member_access |
Undocumented |
Function | analyze_type_type_member_access |
Undocumented |
Function | analyze_typeddict_access |
Undocumented |
Function | analyze_union_member_access |
Undocumented |
Function | analyze_var |
Analyze access to an attribute via a Var node. |
Function | check_final_member |
Give an error if the name being assigned was declared as final. |
Function | check_self_arg |
Check that an instance has a valid type for a method with annotated 'self'. |
Function | freeze_type_vars |
Undocumented |
Function | instance_alias_type |
Type of a type alias node targeting an instance, when appears in runtime context. |
Function | is_valid_constructor |
Does this node represents a valid constructor method? |
Function | lookup_member_var_or_accessor |
Find the attribute/accessor node that refers to a member of a type. |
Function | type_object_type |
Return the type of a type object. |
Function | _analyze_member_access |
Undocumented |
Instantiate type variables during analyze_class_attribute_access, e.g T and Q in the following:
class B(A[str]): pass B.foo()
t: Declared type of the method (or property) isuper: Current instance mapped to the superclass where method was defined, this
is usually done by map_instance_to_supertype()
is_classmethod: True if this method is decorated with @classmethod original_type: The value of the type B in the expression B.foo() or the corresponding
component in case of a union (this is used to bind the self-types)
original_vars: Type variables of the class callable on which the method was accessed
Parameters | |
t:ProperType | Undocumented |
isuper:Optional[ | Undocumented |
is_classmethod:bool | Undocumented |
original_type:Type | Undocumented |
original_vars:Optional[ | Undocumented |
Returns | |
Type | Undocumented |
Analyze access to an attribute on a class object.
itype is the return type of the class object callable, original_type is the type of E in the expression E.var, original_vars are type variables of the class callable (for generic classes).
Parameters | |
itype:Instance | Undocumented |
name:str | Undocumented |
mx:MemberContext | Undocumented |
override_info:Optional[ | Undocumented |
original_vars:Optional[ | Undocumented |
Returns | |
Optional[ | Undocumented |
Analyzes the type behind method access.
The function itself can possibly be decorated. See: https://github.com/python/mypy/issues/10409
Parameters | |
defn:Union[ | Undocumented |
itype:Instance | Undocumented |
info:TypeInfo | Undocumented |
self_type:Optional[ | Undocumented |
name:str | Undocumented |
mx:MemberContext | Undocumented |
Returns | |
Type | Undocumented |
Type check descriptor access.
mx: The current member access context.
Parameters | |
descriptor_type:Type | Undocumented |
mx:MemberContext | Undocumented |
Returns | |
Type | Undocumented |
Undocumented
Parameters | |
itype:Instance | Undocumented |
name:str | Undocumented |
mx:MemberContext | Undocumented |
Returns | |
Optional[ | Undocumented |
Undocumented
Parameters | |
name:str | Undocumented |
typ:Instance | Undocumented |
mx:MemberContext | Undocumented |
override_info:Optional[ | Undocumented |
Returns | |
Type | Undocumented |
Return the type of attribute 'name' of 'typ'.
The actual implementation is in '_analyze_member_access' and this docstring also applies to it.
This is a general operation that supports various different variations:
- lvalue or non-lvalue access (setter or getter access)
- supertype access when using super() (is_super == True and 'override_info' should refer to the supertype)
'original_type' is the most precise inferred or declared type of the base object that we have available. When looking for an attribute of 'typ', we may perform recursive calls targeting the fallback type, and 'typ' may become some supertype of 'original_type'. 'original_type' is always preserved as the 'typ' type used in the initial, non-recursive call. The 'self_type' is a component of 'original_type' to which generic self should be bound (a narrower type that has a fallback to instance). Currently this is used only for union types.
'module_symbol_table' is passed to this function if 'typ' is actually a module and we want to keep track of the available attributes of the module (since they are not available via the type object directly)
Parameters | |
name:str | Undocumented |
typ:Type | Undocumented |
context:Context | Undocumented |
is_lvalue:bool | Undocumented |
is_super:bool | Undocumented |
is_operator:bool | Undocumented |
msg:MessageBuilder | Undocumented |
original_type:Type | Undocumented |
chk:mypy.checker.TypeChecker | Undocumented |
override_info:Optional[ | Undocumented |
in_literal_context:bool | Undocumented |
self_type:Optional[ | Undocumented |
module_symbol_table:Optional[ | Undocumented |
Returns | |
Type | Undocumented |
Analyse attribute access that does not target a method.
This is logically part of analyze_member_access and the arguments are similar.
original_type is the type of E in the expression E.var
Parameters | |
name:str | Undocumented |
itype:Instance | Undocumented |
info:TypeInfo | Undocumented |
mx:MemberContext | Undocumented |
Returns | |
Type | Undocumented |
Undocumented
Parameters | |
name:str | Undocumented |
typ:NoneType | Undocumented |
mx:MemberContext | Undocumented |
Returns | |
Type | Undocumented |
Undocumented
Parameters | |
name:str | Undocumented |
typ:FunctionLike | Undocumented |
mx:MemberContext | Undocumented |
Returns | |
Type | Undocumented |
Undocumented
Parameters | |
name:str | Undocumented |
typ:TypeType | Undocumented |
mx:MemberContext | Undocumented |
override_info:Optional[ | Undocumented |
Returns | |
Type | Undocumented |
Undocumented
Parameters | |
name:str | Undocumented |
typ:TypedDictType | Undocumented |
mx:MemberContext | Undocumented |
override_info:Optional[ | Undocumented |
Returns | |
Type | Undocumented |
Undocumented
Parameters | |
name:str | Undocumented |
typ:UnionType | Undocumented |
mx:MemberContext | Undocumented |
Returns | |
Type | Undocumented |
Analyze access to an attribute via a Var node.
This is conceptually part of analyze_member_access and the arguments are similar.
itype is the class object in which var is defined original_type is the type of E in the expression E.var if implicit is True, the original Var was created as an assignment to self
Parameters | |
name:str | Undocumented |
var:Var | Undocumented |
itype:Instance | Undocumented |
info:TypeInfo | Undocumented |
mx:MemberContext | Undocumented |
implicit:bool | Undocumented |
Returns | |
Type | Undocumented |
Parameters | |
name:str | Undocumented |
info:TypeInfo | Undocumented |
msg:MessageBuilder | Undocumented |
ctx:Context | Undocumented |
Check that an instance has a valid type for a method with annotated 'self'.
then for 'x.f' we check that meet(type(x), A) <: S. If the method is overloaded, we select only overloads items that satisfy this requirement. If there are no matching overloads, an error is generated.
Note: dispatched_arg_type uses a meet to select a relevant item in case if the original type of 'x' is a union. This is done because several special methods treat union types in ad-hoc manner, so we can't use MemberContext.self_type yet.
Parameters | |
functype:FunctionLike | Undocumented |
dispatched_arg_type:Type | Undocumented |
is_classmethod:bool | Undocumented |
context:Context | Undocumented |
name:str | Undocumented |
msg:MessageBuilder | Undocumented |
Returns | |
FunctionLike | Undocumented |
Does this node represents a valid constructor method?
This includes normal functions, overloaded functions, and decorators that return a callable type.
Parameters | |
n:Optional[ | Undocumented |
Returns | |
bool | Undocumented |
Parameters | |
info:TypeInfo | Undocumented |
name:str | Undocumented |
is_lvalue:bool | Undocumented |
Returns | |
Optional[ | Undocumented |
Return the type of a type object.
For a generic type G with type variables T and S the type is generally of form
Callable[..., G[T, S]]
where ... are argument types for the __init__/__new__ method (without the self argument). Also, the fallback type will be 'type' instead of 'function'.
Parameters | |
info:TypeInfo | Undocumented |
named_type:Callable[ | Undocumented |
Returns | |
ProperType | Undocumented |
Undocumented
Parameters | |
name:str | Undocumented |
typ:Type | Undocumented |
mx:MemberContext | Undocumented |
override_info:Optional[ | Undocumented |
Returns | |
Type | Undocumented |