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

Method has_no_attr

mypy/messages.py:335–540  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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

Callers 1

report_missing_attributeFunction · 0.80

Calls 15

failMethod · 0.95
get_proper_typeFunction · 0.90
isinstanceFunction · 0.85
format_typeFunction · 0.85
setClass · 0.85
best_matchesFunction · 0.85
pretty_seqFunction · 0.85
format_type_distinctlyFunction · 0.85
anyFunction · 0.85
typeClass · 0.85

Tested by

no test coverage detected