8000 Update documentation to better reflect new directory structure. (#4976) · python/typeshed@e70d069 · GitHub
[go: up one dir, main page]

Skip to content

Commit e70d069

Browse files
ilevkivskyiIvan Levkivskyi
and
Ivan Levkivskyi
authored
Update documentation to better reflect new directory structure. (#4976)
See #2491 for previous discussion. Co-authored-by: Ivan Levkivskyi <ilevkivskyi@dropbox.com>
1 parent 18a229d commit e70d069

File tree

2 files changed

+66
-51
lines changed

2 files changed

+66
-51
lines changed

CONTRIBUTING.md

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -308,30 +308,19 @@ contributors.
308308

309309
### Stub versioning
310310

311-
There are separate directories for `stdlib` and `third_party` stubs.
312-
Within those, there are separate directories for different versions of
313-
Python the stubs target.
314-
315-
The directory name indicates the major version of Python that a stub targets
316-
and optionally the lowest minor version, with the exception of the `2and3`
317-
directory which applies to both Python 2 and 3.
318-
319-
For example, stubs in the `3` directory will be applied to all versions of
320-
Python 3, though stubs in the `3.7` directory will only be applied to versions
321-
3.7 and above. However, stubs in the `2` directory will not be applied to
322-
Python 3.
323-
324-
It is preferred to use a single stub in the more generic directory that
325-
conditionally targets specific versions when needed, as opposed
326-
to maintaining multiple stub files within more specific directories. Similarly,
327-
if the given library works on both Python 2 and Python 3, prefer to put your
328-
stubs in the `2and3` directory, unless the types are so different that the stubs
329-
become unreadable that way.
330-
331-
You can use checks like `if sys.version_info >= (3, 8):` to denote new
332-
functionality introduced in a given Python version or solve type
333-
differences. When doing so, only use one-tuples or two-tuples. This is
334-
because:
311+
There are separate directories for `stdlib` (standard library) and `stubs`
312+
(all other stubs). For standard library stubs Python version support is
313+
given in `VERSIONS` file. Each line in this file is a module or package name
314+
followed by `: `, followed by the oldest *supported* Python version where
315+
the module is available. For third party packages, the Python version support
316+
(2 and/or 3 only, no finer grained version is supported) is indicated in the
317+
corresponding `METADATA.toml` file as `python2 = (True|False)` (defaults to
318+
`False`) and `python3 = (True|False)` (defaults to `True`).
319+
320+
It is preferred to use a single stub for every module. You can use checks
321+
like `if sys.version_info >= (3, 8):` to denote new functionality introduced
322+
in a given Python version or solve type differences. When doing so, only use
323+
one-tuples or two-tuples. This is because:
335324

336325
* mypy doesn't support more fine-grained version checks; and more
337326
importantly
@@ -353,10 +342,28 @@ harmless. This is a strictly better compromise than using the latter
353342
two forms, which would generate false positive errors for correct use
354343
under Python 3.7.4.
355344

345+
If it is not possible to generate combined stubs for all Python versions
346+
in a single file, you can split Python 2 and Python 3 stubs and place Python 2
347+
stubs into `@python2` subdirectory for corresponding distribution. Note that
348+
you don't need `@python2` in most cases, if your package supports Python 2,
349+
just put the stubs at root of the distribution directory, and put
350+
`python2 = True` in `METADATA.toml`.
351+
356352
Note: in its current implementation, typeshed cannot contain stubs for
357353
multiple versions of the same third-party library. Prefer to generate
358354
stubs for the latest version released on PyPI at the time of your
359-
stubbing.
355+
stubbing. The oldest version of the library for which the stubs are still
356+
applicable (i.e. reflect the actual runtime behaviour) can be indicated
357+
in `METADATA.toml` as `version = "x.y"`. Note that only two most significant
358+
version levels are supported (i.e. only single dot). When a significant change
359+
is made in the library, the version of the stub should be bumped (note that
360+
previous versions are still available on PyPI).
361+
362+
Internal typeshed machinery will periodically build and upload modified
363+
third party packages to PyPI, each time this happens the least significant
364+
version level is incremented. For example, if `stubs/foo/METADATA.toml` has
365+
`version = "x.y"` the package on PyPI will be updated from `types-foo-x.y.n`
366+
to `types-foo-x.y.n+1`.
360367

361368
### What to do when a project's documentation and implementation disagree
362369

README.md

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,20 @@ Typeshed supports Python versions 2.7 and 3.6 and up.
2323

2424
If you're just using mypy (or pytype or PyCharm), as opposed to
2525
developing it, you don't need to interact with the typeshed repo at
26-
all: a copy of typeshed is bundled with mypy.
26+
all: a copy of standard library part of typeshed is bundled with mypy.
27+
And type stubs for third party packages and modules you are using can
28+
be installed from PyPI. For example, if you are using `six` and `requests`,
29+
you can install the type stubs using
2730

28-
When you use a checked-out clone of the mypy repo, a copy of typeshed
29-
should be included as a submodule, using
31+
$ pip install types-six types-requests
3032

31-
$ git clone --recurse-submodules https://github.com/python/mypy.git
33+
These PyPI packages follow [PEP 561](http://www.python.org/dev/peps/pep-0561/)
34+
and are automatically generated by typeshed internal machinery. Also starting
35+
from version 0.900 mypy will provide an option to automatically install missing
36+
type stub packages (if found on PyPI).
3237

33-
or
34-
35-
$ git clone https://github.com/python/mypy.git
36-
$ cd mypy
37-
$ git submodule init
38-
$ git submodule update
39-
40-
and occasionally you will have to repeat the final command (`git
41-
submodule update`) to pull in changes made in the upstream typeshed
42-
repo.
43-
44-
PyCharm and pytype similarly include a copy of typeshed. The one in
45-
pytype can be updated in the same way if you are working with the
46-
pytype repo.
38+
PyCharm, pytype etc. work in a similar way, for more details see documentation
39+
for the type-checking tool you are using.
4740

4841
## Format
4942

@@ -63,16 +56,31 @@ coding style used in typeshed.
6356

6457
### stdlib
6558

66-
This contains stubs for modules the Python standard library -- which
59+
This contains stubs for modules in the Python standard library -- which
6760
includes pure Python modules, dynamically loaded extension modules,
68-
hard-linked extension modules, and the builtins.
61+
hard-linked extension modules, and the builtins. `VERSIONS` file lists
62+
the oldest *supported* Python version where the module is available.
63+
In the `stdlib/@python2` subdirectory you can find Python 2 versions of
64+
the stub files that must be kept different for Python 2 and 3, like
65+
`builtins.pyi`.
6966

70-
### third_party
67+
### stubs
7168

7269
Modules that are not shipped with Python but have a type description in Python
73-
go into `third_party`. Since these modules can behave differently for different
74-
versions of Python, `third_party` has version subdirectories, just like
75-
`stdlib`.
70+
go into `stubs`. Each subdirectory there represents a PyPI distribution, and
71+
contains the following:
72+
* `METADATA.toml` that specifies oldest version of the source library for
73+
which the stubs are applicable, supported Python versions (Python 3 defaults
74+
to `True`, Python 2 defaults to `False`), and dependency on other type stub
75+
packages.
76+
* Stubs (i.e. `*.pyi` files) for packages and modules that are shipped in the
77+
source distribution. Similar to standard library, if the Python 2 version of
78+
the stubs must be kept *separate*, it can be put in a `@python` subdirectory.
79+
* (Rarely) some docs specific to a given type stub package in `README` file.
80+
81+
No other files are allowed in `stdlib` and `stubs`. When a third party stub is
82+
modified, an updated version of the corresponding distribution will be
83+
automatically uploaded to PyPI shortly (within few hours).
7684

7785
For more information on directory structure and stub versioning, see
7886
[the relevant section of CONTRIBUTING.md](
@@ -87,8 +95,8 @@ following criteria is met:
8795

8896
## Contributing
8997

90-
Please read [CONTRIBUTING.md](CONTRIBUTING.md) before submitting pull
91-
requests. If you have questions related to contributing, drop by the [typing Gitter](https://gitter.im/python/typing).
98+
Please read [CONTRIBUTING.md](CONTRIBUTING.md) before submitting pull requests.
99+
If you have questions related to contributing, drop by the [typing Gitter](https://gitter.im/python/typing).
92100

93101
## Running the tests
94102

0 commit comments

Comments
 (0)
0