(
stub: nodes.TypeInfo, runtime: type[Any], object_path: list[str]
)
| 473 | |
| 474 | |
| 475 | def _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 | |
| 514 | SIZEOF_PYOBJECT = struct.calcsize("P") |
no test coverage detected
searching dependent graphs…