@@ -308,30 +308,19 @@ contributors.
308
308
309
309
### Stub versioning
310
310
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:
335
324
336
325
* mypy doesn't support more fine-grained version checks; and more
337
326
importantly
@@ -353,10 +342,28 @@ harmless. This is a strictly better compromise than using the latter
353
342
two forms, which would generate false positive errors for correct use
354
343
under Python 3.7.4.
355
344
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
+
356
352
Note: in its current implementation, typeshed cannot contain stubs for
357
353
multiple versions of the same third-party library. Prefer to generate
358
354
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 ` .
360
367
361
368
### What to do when a project's documentation and implementation disagree
362
369
0 commit comments