ITADN

How to extend `warnings.deprecated`?

#2256Openflying-sheep 创建于 2026-04-09
topic: documentation
F
flying-sheepcommented
We need more metadata for our deprecation decorator, but the spec doesn’t say *how* `deprecated` marks an API. So the only way to mark something as deprecated it is by creating an API with the same exact signature and replace it with `warnings.deprecated` at the type level: ```python if TYPE_CHECKING: from warnings import deprecated else: def deprecated[F](msg: str) -> Callable[[F], F]: ... ``` We need to define `deprecated(msg: str, version: packaging.Version)` and have it work with the type system. How?
2 条评论