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

Function _verify_static_class_methods

mypy/stubtest.py:765–791  ·  view source on GitHub ↗
(
    stub: nodes.FuncBase, runtime: Any, static_runtime: MaybeMissing[Any], object_path: list[str]
)

Source from the content-addressed store, hash-verified

763
764
765def _verify_static_class_methods(
766 stub: nodes.FuncBase, runtime: Any, static_runtime: MaybeMissing[Any], object_path: list[str]
767) -> Iterator[str]:
768 if stub.name in ("__new__", "__init_subclass__", "__class_getitem__"):
769 # Special cased by Python, so don't bother checking
770 return
771 if inspect.isbuiltin(runtime):
772 # The isinstance checks don't work reliably for builtins, e.g. datetime.datetime.now, so do
773 # something a little hacky that seems to work well
774 probably_class_method = isinstance(getattr(runtime, "__self__", None), type)
775 if probably_class_method and not stub.is_class:
776 yield "runtime is a classmethod but stub is not"
777 if not probably_class_method and stub.is_class:
778 yield "stub is a classmethod but runtime is not"
779 return
780
781 if static_runtime is MISSING:
782 return
783
784 if isinstance(static_runtime, classmethod) and not stub.is_class:
785 yield "runtime is a classmethod but stub is not"
786 if not isinstance(static_runtime, classmethod) and stub.is_class:
787 yield "stub is a classmethod but runtime is not"
788 if isinstance(static_runtime, staticmethod) and not stub.is_static:
789 yield "runtime is a staticmethod but stub is not"
790 if not isinstance(static_runtime, staticmethod) and stub.is_static:
791 yield "stub is a staticmethod but runtime is not"
792
793
794def _verify_arg_name(

Callers 2

verify_funcitemFunction · 0.85
verify_overloadedfuncdefFunction · 0.85

Calls 2

isinstanceFunction · 0.85
getattrFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…