Debian Codegraph @

CONTRIBUTING.md

raw
1 Code in this repository should follow CPython's style guidelines and
2 contributors need to sign the PSF Contributor Agreement.
3
4 # typing\_extensions
5
6 The `typing_extensions` module provides a way to access new features from the standard
7 library `typing` module in older versions of Python. For example, Python 3.10 adds
8 `typing.TypeGuard`, but users of older versions of Python can use `typing_extensions` to
9 use `TypeGuard` in their code even if they are unable to upgrade to Python 3.10.
10
11 If you contribute the runtime implementation of a new `typing` feature to CPython, you
12 are encouraged to also implement the feature in `typing_extensions`. Because the runtime
13 implementation of much of the infrastructure in the `typing` module has changed over
14 time, this may require different code for some older Python versions.
15
16 `typing_extensions` may also include experimental features that are not yet part of the
17 standard library, so that users can experiment with them before they are added to the
18 standard library. Such features should already be specified in a PEP or merged into
19 CPython's `main` branch.
20
21 # Versioning scheme
22
23 Starting with version 4.0.0, `typing_extensions` uses
24 [Semantic Versioning](https://semver.org/). See the documentation
25 for more detail.
26
27 ## Development version
28 After a release the version is increased once in [pyproject.toml](/pyproject.toml) and
29 appended with a `.dev` suffix, e.g. `4.0.1.dev`.
30 Further subsequent updates are not planned between releases.
31
32 # Type stubs
33
34 A stub file for `typing_extensions` is maintained
35 [in typeshed](https://github.com/python/typeshed/blob/main/stdlib/typing_extensions.pyi).
36 Because of the special status that `typing_extensions` holds in the typing ecosystem,
37 the stubs are placed in the standard library in typeshed and distributed as
38 part of the stubs bundled with individual type checkers.
39
40 # Running tests
41
42 Testing `typing_extensions` can be tricky because many development tools depend on
43 `typing_extensions`, so you may end up testing some installed version of the library,
44 rather than your local code.
45
46 The simplest way to run the tests locally is:
47
48 - `cd src/`
49 - `python test_typing_extensions.py`
50
51 Alternatively, you can invoke `unittest` explicitly:
52
53 - `python -m unittest test_typing_extensions.py`
54
55 Running these commands in the `src/` directory ensures that the local file
56 `typing_extensions.py` is used, instead of any other version of the library you
57 may have installed.
58
59 # Building the documentation
60
61 To build the documentation in nitpicky mode and treat warnings as errors, run:
62
63 ```
64 uvx --from sphinx sphinx-build -n -W -b html doc doc/_build/html
65 ```
66
67 The generated HTML documentation is written to `doc/_build/html`.
68
69 # Linting
70
71 Linting is done via pre-commit. We recommend running pre-commit via a tool such
72 as [uv](https://docs.astral.sh/uv/) or [pipx](https://pipx.pypa.io/stable/) so
73 that pre-commit and its dependencies are installed into an isolated environment
74 located outside your `typing_extensions` clone. Running pre-commit this way
75 ensures that you don't accidentally install a version of `typing_extensions`
76 from PyPI into a virtual environment inside your `typing_extensions` clone,
77 which could easily happen if pre-commit depended (directly or indirectly) on
78 `typing_extensions`. If a version of `typing_extensions` from PyPI *was*
79 installed into a project-local virtual environment, it could lead to
80 unpredictable results when running `typing_extensions` tests locally.
81
82 To run the linters using uv:
83
84 ```
85 uvx pre-commit run -a
86 ```
87
88 Or using pipx:
89
90 ```
91 pipx run pre-commit run -a
92 ```
93
94 # Workflow for PyPI releases
95
96 - Make sure you follow the versioning policy in the documentation
97 (e.g., release candidates before any feature release, do not release development versions)
98
99 - Ensure that GitHub Actions reports no errors.
100
101 - Check that `CHANGELOG.md` accurately reflects all important changes committed to `main` since the previous release.
102
103 - Update the version number in `typing_extensions/pyproject.toml` and in
104 `typing_extensions/CHANGELOG.md`.
105
106 - Create a new GitHub release at https://github.com/python/typing_extensions/releases/new.
107 Details:
108 - The tag should be just the version number, e.g. `4.1.1`.
109 - Copy the release notes from `CHANGELOG.md`.
110
111 - Release automation will finish the release. You'll have to manually
112 approve the last step before upload.
113
114 - After the release has been published on PyPI upgrade the version in number in [pyproject.toml](/pyproject.toml) to a `dev` version of the next planned release. For example, change 4.1.1 to 4.X.X.dev, see also [Development versions](#development-version). # TODO decide on major vs. minor increase.