Skip to content

[3.7] bpo-35581: Document @typing.type_check_only (GH-11312) #12813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,24 @@ The module defines the following classes, functions and decorators:
This wraps the decorator with something that wraps the decorated
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

Special type indicating an unconstrained type.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@typing.type_check_only now allows type stubs to mark functions and classes not available during runtime.