[Python-checkins] bpo-35581: Document @typing.type_check_only (GH-11312)

Miss Islington (bot) webhook-mailer at python.org
Fri Apr 12 18:48:02 EDT 2019


https://github.com/python/cpython/commit/b759a2c5b9612a03c8b30514aa93444268931e5e
commit: b759a2c5b9612a03c8b30514aa93444268931e5e
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-04-12T15:47:57-07:00
summary:

bpo-35581: Document @typing.type_check_only (GH-11312)

(cherry picked from commit 1e8295402bf5e81d327ed2b5eb88a6b6de449d63)

Co-authored-by: Sebastian Rittau <srittau at rittau.biz>

files:
A Misc/NEWS.d/next/Documentation/2018-12-25-12-56-57.bpo-35581.aA7r6T.rst
M Doc/library/typing.rst

diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index 6f1c85feb0eb..9f6757c2864c 100644
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -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.
diff --git a/Misc/NEWS.d/next/Documentation/2018-12-25-12-56-57.bpo-35581.aA7r6T.rst b/Misc/NEWS.d/next/Documentation/2018-12-25-12-56-57.bpo-35581.aA7r6T.rst
new file mode 100644
index 000000000000..2fad3003e3b6
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2018-12-25-12-56-57.bpo-35581.aA7r6T.rst
@@ -0,0 +1 @@
+ at typing.type_check_only now allows type stubs to mark functions and classes not available during runtime.
\ No newline at end of file



More information about the Python-checkins mailing list