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

Function analyze_member_access

mypy/checkmember.py:166–239  ·  view source on GitHub ↗

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: 1. lvalue or non-lvalue access (setter or getter access) 2.

(
    name: str,
    typ: Type,
    context: Context,
    *,
    is_lvalue: bool,
    is_super: bool,
    is_operator: bool,
    original_type: Type,
    chk: TypeCheckerSharedApi,
    override_info: TypeInfo | None = None,
    in_literal_context: bool = False,
    self_type: Type | None = None,
    module_symbol_table: SymbolTable | None = None,
    no_deferral: bool = False,
    is_self: bool = False,
    rvalue: Expression | None = None,
    suppress_errors: bool = False,
)

Source from the content-addressed store, hash-verified

164
165
166def analyze_member_access(
167 name: str,
168 typ: Type,
169 context: Context,
170 *,
171 is_lvalue: bool,
172 is_super: bool,
173 is_operator: bool,
174 original_type: Type,
175 chk: TypeCheckerSharedApi,
176 override_info: TypeInfo | None = None,
177 in_literal_context: bool = False,
178 self_type: Type | None = None,
179 module_symbol_table: SymbolTable | None = None,
180 no_deferral: bool = False,
181 is_self: bool = False,
182 rvalue: Expression | None = None,
183 suppress_errors: bool = False,
184) -> Type:
185 """Return the type of attribute 'name' of 'typ'.
186
187 The actual implementation is in '_analyze_member_access' and this docstring
188 also applies to it.
189
190 This is a general operation that supports various different variations:
191
192 1. lvalue or non-lvalue access (setter or getter access)
193 2. supertype access when using super() (is_super == True and
194 'override_info' should refer to the supertype)
195
196 'original_type' is the most precise inferred or declared type of the base object
197 that we have available. When looking for an attribute of 'typ', we may perform
198 recursive calls targeting the fallback type, and 'typ' may become some supertype
199 of 'original_type'. 'original_type' is always preserved as the 'typ' type used in
200 the initial, non-recursive call. The 'self_type' is a component of 'original_type'
201 to which generic self should be bound (a narrower type that has a fallback to instance).
202 Currently, this is used only for union types.
203
204 'module_symbol_table' is passed to this function if 'typ' is actually a module,
205 and we want to keep track of the available attributes of the module (since they
206 are not available via the type object directly)
207
208 'rvalue' can be provided optionally to infer better setter type when is_lvalue is True,
209 most notably this helps for descriptors with overloaded __set__() method.
210
211 'suppress_errors' will skip any logic that is only needed to generate error messages.
212 Note that this more of a performance optimization, one should not rely on this to not
213 show any messages, as some may be show e.g. by callbacks called here,
214 use msg.filter_errors(), if needed.
215 """
216 mx = MemberContext(
217 is_lvalue=is_lvalue,
218 is_super=is_super,
219 is_operator=is_operator,
220 original_type=original_type,
221 context=context,
222 chk=chk,
223 self_type=self_type,

Callers 11

extract_callable_typeMethod · 0.90
replay_lookupMethod · 0.90
has_valid_attributeMethod · 0.90
check_union_call_exprMethod · 0.90
check_callMethod · 0.90
lookup_operatorMethod · 0.90
visit_super_exprMethod · 0.90
visit_class_patternMethod · 0.90

Calls 4

get_proper_typeFunction · 0.90
MemberContextClass · 0.85
_analyze_member_accessFunction · 0.85
isinstanceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…