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

Function _verify_final

mypy/stubtest.py:475–511  ·  view source on GitHub ↗
(
    stub: nodes.TypeInfo, runtime: type[Any], object_path: list[str]
)

Source from the content-addressed store, hash-verified

473
474
475def _verify_final(
476 stub: nodes.TypeInfo, runtime: type[Any], object_path: list[str]
477) -> Iterator[Error]:
478 try:
479
480 class SubClass(runtime): # type: ignore[misc]
481 pass
482
483 except TypeError:
484 # Enum classes are implicitly @final
485 if not stub.is_final and not issubclass(runtime, enum.Enum):
486 yield Error(
487 object_path,
488 "cannot be subclassed at runtime, but isn't marked with @final in the stub",
489 stub,
490 runtime,
491 stub_desc=repr(stub),
492 )
493 except Exception:
494 # The class probably wants its subclasses to do something special.
495 # Examples: ctypes.Array, ctypes._SimpleCData
496 pass
497
498 # Runtime class might be annotated with `@final`:
499 try:
500 runtime_final = getattr(runtime, "__final__", False)
501 except Exception:
502 runtime_final = False
503
504 if runtime_final and not stub.is_final:
505 yield Error(
506 object_path,
507 "has `__final__` attribute, but isn't marked with @final in the stub",
508 stub,
509 runtime,
510 stub_desc=repr(stub),
511 )
512
513
514SIZEOF_PYOBJECT = struct.calcsize("P")

Callers 1

verify_typeinfoFunction · 0.85

Calls 3

ErrorClass · 0.85
reprFunction · 0.85
getattrFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…