Skip to content

Commit e478b10

Browse files
committed
docs: document that stubtest ignores private stub names
Add a section to the stubtest documentation explaining that names beginning with a leading underscore are treated as private to the stub and will not be flagged if missing at runtime. Fixes #15414
1 parent 82e8498 commit e478b10

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎docs/source/stubtest.rst‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,29 @@ test Python's official collection of library stubs,
4545

4646
stubtest will import and execute Python code from the packages it checks.
4747

48+
Private stub names
49+
******************
50+
51+
Stubtest treats names in stubs that begin with a leading underscore (e.g.,
52+
``_T``) as private to the stub. If such a name does not exist at runtime,
53+
stubtest will not report an error. This is commonly used for :py:class:`TypeVar
54+
<typing.TypeVar>` definitions and other type-checking-only helpers that do not
55+
need to be present at runtime.
56+
57+
For example, the following stub will not produce a "not present at runtime"
58+
error, even though ``_T`` is missing from the implementation:
59+
60+
.. code-block:: python
61+
62+
from typing import Generic, TypeVar
63+
64+
_T = TypeVar("_T")
65+
66+
class SomeClass(Generic[_T]): ...
67+
68+
Note that dunder names (such as ``__init__``) are not treated as private by
69+
this rule.
70+
4871
Example
4972
*******
5073

0 commit comments

Comments
 (0)