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

Function prepare_methods_and_attributes

mypyc/irbuild/prepare.py:530–579  ·  view source on GitHub ↗

Populate attribute and method declarations.

(
    cdef: ClassDef,
    ir: ClassIR,
    path: str,
    module_name: str,
    errors: Errors,
    mapper: Mapper,
    options: CompilerOptions,
)

Source from the content-addressed store, hash-verified

528
529
530def prepare_methods_and_attributes(
531 cdef: ClassDef,
532 ir: ClassIR,
533 path: str,
534 module_name: str,
535 errors: Errors,
536 mapper: Mapper,
537 options: CompilerOptions,
538) -> None:
539 """Populate attribute and method declarations."""
540 info = cdef.info
541 for name, node in info.names.items():
542 # Currently all plugin generated methods are dummies and not included.
543 if node.plugin_generated:
544 continue
545
546 if isinstance(node.node, Var):
547 assert node.node.type, "Class member %s missing type" % name
548 if not node.node.is_classvar and name not in ("__slots__", "__deletable__"):
549 attr_rtype = mapper.type_to_rtype(node.node.type)
550 if ir.is_trait and attr_rtype.error_overlap:
551 # Traits don't have attribute definedness bitmaps, so use
552 # property accessor methods to access attributes that need them.
553 # We will generate accessor implementations that use the class bitmap
554 # for any concrete subclasses.
555 add_getter_declaration(ir, name, attr_rtype, module_name)
556 add_setter_declaration(ir, name, attr_rtype, module_name)
557 ir.attributes[name] = attr_rtype
558 elif isinstance(node.node, (FuncDef, Decorator)):
559 prepare_method_def(ir, module_name, cdef, mapper, node.node, options)
560 elif isinstance(node.node, OverloadedFuncDef):
561 # Handle case for property with both a getter and a setter
562 if node.node.is_property:
563 if is_valid_multipart_property_def(node.node):
564 for item in node.node.items:
565 prepare_method_def(ir, module_name, cdef, mapper, item, options)
566 else:
567 errors.error("Unsupported property decorator semantics", path, cdef.line)
568
569 # Handle case for regular function overload
570 else:
571 if not node.node.impl:
572 errors.error(
573 "Overloads without implementation are not supported", path, cdef.line
574 )
575 else:
576 prepare_method_def(ir, module_name, cdef, mapper, node.node.impl, options)
577
578 if ir.builtin_base:
579 ir.attributes.clear()
580
581
582def prepare_implicit_property_accessors(

Callers 1

prepare_class_defFunction · 0.85

Calls 9

isinstanceFunction · 0.85
add_getter_declarationFunction · 0.85
add_setter_declarationFunction · 0.85
prepare_method_defFunction · 0.85
itemsMethod · 0.45
type_to_rtypeMethod · 0.45
errorMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…