MCPcopy
hub / github.com/python/mypy / apply_hooks_to_class

Function apply_hooks_to_class

mypy/semanal_main.py:480–516  ·  view source on GitHub ↗
(
    self: SemanticAnalyzer,
    module: str,
    info: TypeInfo,
    options: Options,
    file_node: MypyFile,
    errors: Errors,
)

Source from the content-addressed store, hash-verified

478
479
480def apply_hooks_to_class(
481 self: SemanticAnalyzer,
482 module: str,
483 info: TypeInfo,
484 options: Options,
485 file_node: MypyFile,
486 errors: Errors,
487) -> bool:
488 # TODO: Move more class-related hooks here?
489 defn = info.defn
490 ok = True
491 for decorator in defn.decorators:
492 with self.file_context(file_node, options, info):
493 hook = None
494
495 decorator_name = self.get_fullname_for_hook(decorator)
496 if decorator_name:
497 hook = self.plugin.get_class_decorator_hook_2(decorator_name)
498 # Special case: if the decorator is itself decorated with
499 # typing.dataclass_transform, apply the hook for the dataclasses plugin
500 # TODO: remove special casing here
501 if hook is None and find_dataclass_transform_spec(decorator):
502 hook = dataclasses_plugin.dataclass_class_maker_callback
503
504 if hook:
505 ok = ok and hook(ClassDefContext(defn, decorator, self))
506
507 # Check if the class definition itself triggers a dataclass transform (via a parent class/
508 # metaclass)
509 spec = find_dataclass_transform_spec(info)
510 if spec is not None:
511 with self.file_context(file_node, options, info):
512 # We can't use the normal hook because reason = defn, and ClassDefContext only accepts
513 # an Expression for reason
514 ok = ok and dataclasses_plugin.DataclassTransformer(defn, defn, spec, self).transform()
515
516 return ok
517
518
519def calculate_class_properties(graph: Graph, scc: list[str], errors: Errors) -> None:

Callers 1

apply_class_plugin_hooksFunction · 0.85

Calls 6

ClassDefContextClass · 0.90
file_contextMethod · 0.80
get_fullname_for_hookMethod · 0.80
transformMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…