aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2022-01-04 21:14:39 +0300
committerGitHub <noreply@github.com>2022-01-04 19:14:39 +0100
commit2370371c7258f0b1432c34498ad742783503750d (patch)
tree708aaef84cc948d38c12fbaba1865fb1743ffed2
parentfbd81cd5e0a4061102e2b93de38cf8e0e63ad6bc (diff)
downloadtyping-2370371c7258f0b1432c34498ad742783503750d.tar.gz
Suggest to use `_` prefix for stubs-only types (#1005)
-rw-r--r--docs/source/stubs.rst10
1 files changed, 7 insertions, 3 deletions
diff --git a/docs/source/stubs.rst b/docs/source/stubs.rst
index d5ad685..ae45670 100644
--- a/docs/source/stubs.rst
+++ b/docs/source/stubs.rst
@@ -577,19 +577,21 @@ public method for which a library does not provided a usable runtime type::
from typing import Protocol
- class Readable(Protocol):
+ class _Readable(Protocol):
def read(self) -> str: ...
- def get_reader() -> Readable: ...
+ def get_reader() -> _Readable: ...
Structural Types
----------------
-As seen in the example with ``Readable`` in the previous section, a common use
+As seen in the example with ``_Readable`` in the previous section, a common use
of stub-only objects is to model types that are best described by their
structure. These objects are called protocols [#pep544]_, and it is encouraged
to use them freely to describe simple structural types.
+It is `recommended <private-definitions>`_ to prefix stubs-only object names with ``_``.
+
Incomplete Stubs
----------------
@@ -921,6 +923,8 @@ No::
...
def to_int3(x: str) -> int: pass
+.. _private-definitions:
+
Private Definitions
-------------------