@@ -39,7 +39,7 @@ need fixing.
39
39
40
40
### ... Or create a local development environment
41
41
42
- If you prefer to run the tests & formatting locally, it's
42
+ If you prefer to run the tests and formatting locally, it's
43
43
possible too. Follow platform-specific instructions below.
44
44
For more information about our available tests, see
45
45
[ tests/README.md] ( tests/README.md ) .
@@ -54,7 +54,7 @@ Note that some tests require extra setup steps to install the required dependenc
54
54
### Linux/Mac OS
55
55
56
56
On Linux and Mac OS, you will be able to run the full test suite on Python
57
- 3.9 or 3.10 .
57
+ 3.9, 3.10, or 3.11 .
58
58
To install the necessary requirements, run the following commands from a
59
59
terminal window:
60
60
@@ -94,7 +94,7 @@ also performed by [`Ruff`](https://github.com/astral-sh/ruff) and
94
94
with plugins [ ` flake8-pyi ` ] ( https://github.com/pycqa/flake8-pyi ) ,
95
95
and [ ` flake8-noqa ` ] ( https://github.com/plinss/flake8-noqa ) .
96
96
97
- The repository is equipped with a [ ` pre-commit.ci ` ] ( https://pre-commit.ci/ )
97
+ The repository is equipped with a [ pre-commit.ci] ( https://pre-commit.ci/ )
98
98
configuration file. This means that you don't * need* to do anything yourself to
99
99
run the code formatters or linters. When you push a commit, a bot will run
100
100
those for you right away and add any autofixes to your PR. Anything
@@ -128,9 +128,8 @@ We accept stubs for third-party packages into typeshed as long as:
128
128
129
129
The fastest way to generate new stubs is to use ` scripts/create_baseline_stubs.py ` (see below).
130
130
131
- Stubs for third-party packages
132
- go into ` stubs ` . Each subdirectory there represents a PyPI distribution, and
133
- contains the following:
131
+ Stubs for third-party packages go into the ` stubs ` directory. Each subdirectory
132
+ there represents a PyPI distribution, and contains the following:
134
133
* ` METADATA.toml ` , describing the package. See below for details.
135
134
* Stubs (i.e. ` *.pyi ` files) for packages and modules that are shipped in the
136
135
source distribution.
@@ -193,6 +192,9 @@ supported:
193
192
* ` partial_stub ` (optional): This field marks the type stub package as
194
193
[ partial] ( https://peps.python.org/pep-0561/#partial-stub-packages ) . This is for
195
194
3rd-party stubs that don't cover the entirety of the package's public API.
195
+ * ` requires_python ` (optional): The minimum version of Python required to install
196
+ the type stub package. It must be in the form ` >=3.* ` . If omitted, the oldest
197
+ Python version supported by typeshed is used.
196
198
197
199
In addition, we specify configuration for stubtest in the ` tool.stubtest ` table.
198
200
This has the following keys:
@@ -235,7 +237,7 @@ with what you'd like to do or have ideas that will help you do it.
235
237
236
238
Each Python module is represented by a ` .pyi ` "stub file". This is a
237
239
syntactically valid Python file, although it usually cannot be run by
238
- Python 3 (since forward references don't require string quotes). All
240
+ Python (since forward references don't require string quotes). All
239
241
the methods are empty.
240
242
241
243
Python function annotations ([ PEP 3107] ( https://www.python.org/dev/peps/pep-3107/ ) )
@@ -289,7 +291,7 @@ Supported features include:
289
291
- [ PEP 702] ( https://peps.python.org/pep-0702/ ) (` @deprecated() ` )
290
292
291
293
Features from the ` typing ` module that are not present in all
292
- supported Python 3 versions must be imported from ` typing_extensions `
294
+ supported Python versions must be imported from ` typing_extensions `
293
295
instead in typeshed stubs. This currently affects:
294
296
295
297
- ` TypeAlias ` (new in Python 3.10)
@@ -379,16 +381,16 @@ MAXYEAR: int
379
381
MINYEAR : int
380
382
381
383
class date :
382
- def __new__ (cls : Type[_S] , year : int , month : int , day : int ) -> _S : ...
384
+ def __new__ (cls , year : SupportsIndex , month : SupportsIndex , day : SupportsIndex ) -> Self : ...
383
385
@ classmethod
384
- def fromtimestamp (cls : Type[_S], __timestamp : float ) -> _S : ...
386
+ def fromtimestamp (cls , timestamp : float , / ) -> Self : ...
385
387
@ classmethod
386
- def today (cls : Type[_S] ) -> _S : ...
388
+ def today (cls ) -> Self : ...
387
389
@ classmethod
388
- def fromordinal (cls : Type[_S], __n : int ) -> _S : ...
390
+ def fromordinal (cls , n : int , / ) -> Self : ...
389
391
@ property
390
392
def year (self ) -> int : ...
391
- def replace (self , year : int = ... , month : int = ... , day : int = ... ) -> date : ...
393
+ def replace (self , year : SupportsIndex = ... , month : SupportsIndex = ... , day : SupportsIndex = ... ) -> Self : ...
392
394
def ctime (self ) -> str : ...
393
395
def weekday (self ) -> int : ...
394
396
```
@@ -438,8 +440,8 @@ Some further tips for good type hints:
438
440
` Optional[X] ` ;
439
441
* import collections (` Mapping ` , ` Iterable ` , etc.)
440
442
from ` collections.abc ` instead of ` typing ` ;
441
- * avoid invariant collection types (` list ` , ` dict ` ) in argument
442
- positions , in favor of covariant types like ` Mapping ` or ` Sequence ` ;
443
+ * avoid invariant collection types (` list ` , ` dict ` ) for function
444
+ parameters , in favor of covariant types like ` Mapping ` or ` Sequence ` ;
443
445
* avoid union return types: https://github.com/python/mypy/issues/1693 ;
444
446
* use platform checks like ` if sys.platform == 'win32' ` to denote
445
447
platform-dependent APIs;
@@ -485,8 +487,8 @@ context manager is meant to be subclassed, pick `bool | None`.
485
487
See https://github.com/python/mypy/issues/7214 for more details.
486
488
487
489
` __enter__ ` methods and other methods that return instances of the
488
- current class should be annotated with the ` _typeshed .Self` type
489
- variable ([ example] ( https://github.com/python/typeshed/pull/5698 ) ).
490
+ current class should be annotated with ` typing_extensions .Self`
491
+ ([ example] ( https://github.com/python/typeshed/blob/3581846/stdlib/contextlib.pyi#L151 ) ).
490
492
491
493
### Naming
492
494
@@ -556,7 +558,7 @@ Consider the following (simplified) signature of `re.Match[str].group`:
556
558
557
559
``` python
558
560
class Match :
559
- def group (self , __group : str | int ) -> str | Any: ...
561
+ def group (self , group : str | int , / ) -> str | Any: ...
560
562
```
561
563
562
564
The ` str | Any ` seems unnecessary and weird at first.
0 commit comments