(
name: str, typ: Instance, mx: MemberContext, override_info: TypeInfo | None
)
| 319 | |
| 320 | |
| 321 | def analyze_instance_member_access( |
| 322 | name: str, typ: Instance, mx: MemberContext, override_info: TypeInfo | None |
| 323 | ) -> Type: |
| 324 | info = typ.type |
| 325 | if override_info: |
| 326 | info = override_info |
| 327 | |
| 328 | method = info.get_method(name) |
| 329 | |
| 330 | if name == "__init__" and not mx.is_super and not info.is_final: |
| 331 | if not method or not method.is_final: |
| 332 | # Accessing __init__ in statically typed code would compromise |
| 333 | # type safety unless used via super() or the method/class is final. |
| 334 | mx.fail(message_registry.CANNOT_ACCESS_INIT) |
| 335 | return AnyType(TypeOfAny.from_error) |
| 336 | |
| 337 | # The base object has an instance type. |
| 338 | |
| 339 | if ( |
| 340 | state.find_occurrences |
| 341 | and info.name == state.find_occurrences[0] |
| 342 | and name == state.find_occurrences[1] |
| 343 | and not mx.suppress_errors |
| 344 | ): |
| 345 | mx.msg.note("Occurrence of '{}.{}'".format(*state.find_occurrences), mx.context) |
| 346 | |
| 347 | # Look up the member. First look up the method dictionary. |
| 348 | if method and not isinstance(method, Decorator): |
| 349 | if mx.is_super and not mx.suppress_errors: |
| 350 | validate_super_call(method, mx) |
| 351 | |
| 352 | if method.is_property: |
| 353 | assert isinstance(method, OverloadedFuncDef) |
| 354 | getter = method.items[0] |
| 355 | assert isinstance(getter, Decorator) |
| 356 | if mx.is_lvalue and getter.var.is_settable_property: |
| 357 | mx.chk.warn_deprecated(method.setter, mx.context) |
| 358 | return analyze_var(name, getter.var, typ, mx) |
| 359 | |
| 360 | if mx.is_lvalue and not mx.suppress_errors: |
| 361 | mx.msg.cant_assign_to_method(mx.context) |
| 362 | if not isinstance(method, OverloadedFuncDef): |
| 363 | signature = function_type(method, mx.named_type("builtins.function")) |
| 364 | else: |
| 365 | if method.type is None: |
| 366 | # Overloads may be not ready if they are decorated. Handle this in same |
| 367 | # manner as we would handle a regular decorated function: defer if possible. |
| 368 | if not mx.no_deferral and method.items: |
| 369 | mx.not_ready_callback(method.name, mx.context) |
| 370 | return AnyType(TypeOfAny.special_form) |
| 371 | assert isinstance(method.type, Overloaded) |
| 372 | signature = method.type |
| 373 | if not mx.preserve_type_var_ids: |
| 374 | signature = freshen_all_functions_type_vars(signature) |
| 375 | if not method.is_static: |
| 376 | if isinstance(method, (FuncDef, OverloadedFuncDef)) and method.is_trivial_self: |
| 377 | signature = bind_self_fast(signature, mx.self_type) |
| 378 | else: |
no test coverage detected
searching dependent graphs…