Skip to content

Commit 1e82954

Browse files
srittaugvanrossum
authored andcommitted
bpo-35581: Document @typing.type_check_only (GH-11312)
1 parent 1e2ad6c commit 1e82954

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

Doc/library/typing.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,24 @@ The module defines the following classes, functions and decorators:
951951
This wraps the decorator with something that wraps the decorated
952952
function in :func:`no_type_check`.
953953

954+
.. decorator:: type_check_only
955+
956+
Decorator to mark a class or function to be unavailable at runtime.
957+
958+
This decorator is itself not available at runtime. It is mainly
959+
intended to mark classes that are defined in type stub files if
960+
an implementation returns an instance of a private class::
961+
962+
@type_check_only
963+
class Response: # private or not available at runtime
964+
code: int
965+
def get_header(self, name: str) -> str: ...
966+
967+
def fetch_response() -> Response: ...
968+
969+
Note that returning instances of private classes is not recommended.
970+
It is usually preferable to make such classes public.
971+
954972
.. data:: Any
955973

956974
Special type indicating an unconstrained type.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@typing.type_check_only now allows type stubs to mark functions and classes not available during runtime.

0 commit comments

Comments
 (0)