Skip to content

Commit 6a2232a

Browse files
Improve docs on running stubtest locally (#8822)
Co-authored-by: Shantanu <[email protected]>
1 parent d1375f6 commit 6a2232a

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

tests/README.md

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,27 @@ Run using
102102
This test compares the stdlib stubs against the objects at runtime. Because of
103103
this, the output depends on which version of Python and on what kind of system
104104
it is run.
105-
Thus the easiest way to run this test is via Github Actions on your fork;
106-
if you run it locally, it'll likely complain about system-specific
107-
differences (in e.g, `socket`) that the type system cannot capture.
105+
As such, if you run this test locally, it may complain about system-specific
106+
differences (in e.g, `socket`) that the type system cannot capture or our stubtest settings
107+
in CI do not account for. If you run into this issue, consider opening a draft PR and letting CI
108+
test it automatically (or
109+
[running the test via Github Actions](https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow#running-a-workflow)
110+
on your typeshed fork).
111+
108112
If you need a specific version of Python to repro a CI failure,
109-
[pyenv](https://github.com/pyenv/pyenv) can help.
113+
[pyenv](https://github.com/pyenv/pyenv) can also help.
110114

111115
Due to its dynamic nature, you may run into false positives. In this case, you
112116
can add to the allowlists for each affected Python version in
113117
`tests/stubtest_allowlists`. Please file issues for stubtest false positives
114118
at [mypy](https://github.com/python/mypy/issues).
115119

116-
To run stubtest against third party stubs, it's easiest to use stubtest
117-
directly, with
118-
```
119-
(.venv3)$ python3 -m mypy.stubtest \
120-
--custom-typeshed-dir <path-to-typeshed> \
121-
<third-party-module>
122-
```
123-
stubtest can also help you find things missing from the stubs.
124-
125120
## stubtest\_third\_party.py
126121

122+
:warning: This script downloads and executes arbitrary code from PyPI. Only run
123+
this script locally if you know you can trust the packages you're running
124+
stubtest on.
125+
127126
Run using
128127
```
129128
(.venv3)$ python3 tests/stubtest_third_party.py
@@ -141,6 +140,28 @@ For each distribution, stubtest ignores definitions listed in a `@tests/stubtest
141140
relative to the distribution. Additional packages that are needed to run stubtest for a
142141
distribution can be added to `@tests/requirements-stubtest.txt`.
143142

143+
### Using stubtest to find objects missing from the stubs
144+
145+
By default, stubtest emits an error if a public object is present at runtime
146+
but missing from the stub. However, this behaviour can be disabled using the
147+
`--ignore-missing-stub` option.
148+
149+
Many third-party stubs packages in typeshed are currently incomplete, and so by
150+
default, `stubtest_third_party.py` runs stubtest with the
151+
`--ignore-missing-stub` option to test our third-party stubs. However, this
152+
option is not used if the distribution has `ignore_missing_stub = false` in the
153+
`tool.stubtest` section of its `tests/METADATA.toml` file. This setting
154+
indicates that the package is considered "complete", for example:
155+
https://github.com/python/typeshed/blob/6950c3237065e6e2a9b64810765fec716252d52a/stubs/emoji/METADATA.toml#L3-L4
156+
157+
You can help make typeshed's stubs more complete by adding
158+
`ignore_missing_stub = false` to the `tests/METADATA.toml` file for a
159+
third-party stubs distribution, running stubtest, and then adding things that
160+
stubtest reports to be missing to the stub. However, note that not *everything*
161+
that stubtest reports to be missing should necessarily be added to the stub.
162+
For some implementation details, it is often better to add allowlist entries
163+
for missing objects rather than trying to match the runtime in every detail.
164+
144165
## typecheck\_typeshed.py
145166

146167
Run using

0 commit comments

Comments
 (0)