mirror of
https://github.com/python/cpython.git
synced 2025-09-30 20:31:52 +00:00
bpo-35581: Document @typing.type_check_only (GH-11312)
This commit is contained in:
parent
1e2ad6c275
commit
1e8295402b
2 changed files with 19 additions and 0 deletions
|
@ -951,6 +951,24 @@ The module defines the following classes, functions and decorators:
|
||||||
This wraps the decorator with something that wraps the decorated
|
This wraps the decorator with something that wraps the decorated
|
||||||
function in :func:`no_type_check`.
|
function in :func:`no_type_check`.
|
||||||
|
|
||||||
|
.. decorator:: type_check_only
|
||||||
|
|
||||||
|
Decorator to mark a class or function to be unavailable at runtime.
|
||||||
|
|
||||||
|
This decorator is itself not available at runtime. It is mainly
|
||||||
|
intended to mark classes that are defined in type stub files if
|
||||||
|
an implementation returns an instance of a private class::
|
||||||
|
|
||||||
|
@type_check_only
|
||||||
|
class Response: # private or not available at runtime
|
||||||
|
code: int
|
||||||
|
def get_header(self, name: str) -> str: ...
|
||||||
|
|
||||||
|
def fetch_response() -> Response: ...
|
||||||
|
|
||||||
|
Note that returning instances of private classes is not recommended.
|
||||||
|
It is usually preferable to make such classes public.
|
||||||
|
|
||||||
.. data:: Any
|
.. data:: Any
|
||||||
|
|
||||||
Special type indicating an unconstrained type.
|
Special type indicating an unconstrained type.
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
@typing.type_check_only now allows type stubs to mark functions and classes not available during runtime.
|
Loading…
Add table
Add a link
Reference in a new issue