From 1387a9efa92bf91bd084b7eaaa9d9f3e0c427990 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Sun, 19 Feb 2023 15:21:55 +0300 Subject: [PATCH] Mark `threading.(R)Lock` as `final` (#9753) These are actually factory functions: https://github.com/python/cpython/blob/128379b8cdb88a6d3d7fed24df082c9a654b3fb8/Lib/threading.py#L108 The pure-Python version of `RLock` is, strictly-speaking, subclassable. But you're not *meant* to subclass `RLock`, even if you *can* with the pure-Python version: https://discuss.python.org/t/make-threading-lock-rlock-factory-functions-subclassable/24008/2 --- stdlib/threading.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stdlib/threading.pyi b/stdlib/threading.pyi index c0b344fe7..c01797880 100644 --- a/stdlib/threading.pyi +++ b/stdlib/threading.pyi @@ -3,6 +3,7 @@ from _typeshed import ProfileFunction, TraceFunction from collections.abc import Callable, Iterable, Mapping from types import TracebackType from typing import Any, TypeVar +from typing_extensions import final _T = TypeVar("_T") @@ -101,6 +102,7 @@ class Thread: class _DummyThread(Thread): def __init__(self) -> None: ... +@final class Lock: def __enter__(self) -> bool: ... def __exit__( @@ -110,6 +112,7 @@ class Lock: def release(self) -> None: ... def locked(self) -> bool: ... +@final class _RLock: def acquire(self, blocking: bool = True, timeout: float = -1) -> bool: ... def release(self) -> None: ...