Report a missing or non-accessible member. original_type is the top-level type on which the error occurred. typ is the actual type that is missing the member. These can be different, e.g., in a union, original_type will be the union and typ will be the specific item
(
self,
original_type: Type,
typ: Type,
member: str,
context: Context,
module_symbol_table: SymbolTable | None = None,
)
| 333 | # on them. |
| 334 | |
| 335 | def has_no_attr( |
| 336 | self, |
| 337 | original_type: Type, |
| 338 | typ: Type, |
| 339 | member: str, |
| 340 | context: Context, |
| 341 | module_symbol_table: SymbolTable | None = None, |
| 342 | ) -> ErrorCode | None: |
| 343 | """Report a missing or non-accessible member. |
| 344 | |
| 345 | original_type is the top-level type on which the error occurred. |
| 346 | typ is the actual type that is missing the member. These can be |
| 347 | different, e.g., in a union, original_type will be the union and typ |
| 348 | will be the specific item in the union that does not have the member |
| 349 | attribute. |
| 350 | |
| 351 | 'module_symbol_table' is passed to this function if the type for which we |
| 352 | are trying to get a member was originally a module. The SymbolTable allows |
| 353 | us to look up and suggests attributes of the module since they are not |
| 354 | directly available on original_type |
| 355 | |
| 356 | If member corresponds to an operator, use the corresponding operator |
| 357 | name in the messages. Return the error code that was produced, if any. |
| 358 | """ |
| 359 | original_type = get_proper_type(original_type) |
| 360 | typ = get_proper_type(typ) |
| 361 | |
| 362 | if isinstance(original_type, Instance) and original_type.type.has_readable_member(member): |
| 363 | self.fail(f'Member "{member}" is not assignable', context) |
| 364 | return None |
| 365 | elif member == "__contains__": |
| 366 | self.fail( |
| 367 | f"Unsupported right operand type for in ({format_type(original_type, self.options)})", |
| 368 | context, |
| 369 | code=codes.OPERATOR, |
| 370 | ) |
| 371 | return codes.OPERATOR |
| 372 | elif member in op_methods.values(): |
| 373 | # Access to a binary operator member (e.g. _add). This case does |
| 374 | # not handle indexing operations. |
| 375 | for op, method in op_methods.items(): |
| 376 | if method == member: |
| 377 | self.unsupported_left_operand(op, original_type, context) |
| 378 | return codes.OPERATOR |
| 379 | elif member == "__neg__": |
| 380 | self.fail( |
| 381 | f"Unsupported operand type for unary - ({format_type(original_type, self.options)})", |
| 382 | context, |
| 383 | code=codes.OPERATOR, |
| 384 | ) |
| 385 | return codes.OPERATOR |
| 386 | elif member == "__pos__": |
| 387 | self.fail( |
| 388 | f"Unsupported operand type for unary + ({format_type(original_type, self.options)})", |
| 389 | context, |
| 390 | code=codes.OPERATOR, |
| 391 | ) |
| 392 | return codes.OPERATOR |
no test coverage detected