Skip to content

Commit cbb1ad3

Browse files
authored
Merge branch 'master' into 585
2 parents b8d253f + bedf520 commit cbb1ad3

File tree

9 files changed

+99
-41
lines changed

9 files changed

+99
-41
lines changed

stdlib/VERSIONS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ webbrowser: 2.7-
286286
winreg: 3.0-
287287
winsound: 2.7-
288288
wsgiref: 2.7-
289+
wsgiref.types: 3.11-
289290
xdrlib: 2.7-
290291
xml: 2.7-
291292
xmlrpc: 3.0-

stdlib/_typeshed/wsgi.pyi

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,44 @@
11
# Types to support PEP 3333 (WSGI)
22
#
3+
# Obsolete since Python 3.11: Use wsgiref.types instead.
4+
#
35
# See the README.md file in this directory for more information.
46

7+
import sys
58
from collections.abc import Callable, Iterable
69
from sys import _OptExcInfo
710
from typing import Any, Protocol
811
from typing_extensions import TypeAlias
912

10-
# stable
11-
class StartResponse(Protocol):
12-
def __call__(
13-
self, status: str, headers: list[tuple[str, str]], exc_info: _OptExcInfo | None = ...
14-
) -> Callable[[bytes], Any]: ...
13+
class _Readable(Protocol):
14+
def read(self, size: int = ...) -> bytes: ...
15+
# Optional: def close(self) -> object: ...
1516

16-
WSGIEnvironment: TypeAlias = dict[str, Any] # stable
17-
WSGIApplication: TypeAlias = Callable[[WSGIEnvironment, StartResponse], Iterable[bytes]] # stable
17+
if sys.version_info >= (3, 11):
18+
from wsgiref.types import *
19+
else:
20+
# stable
21+
class StartResponse(Protocol):
22+
def __call__(
23+
self, __status: str, __headers: list[tuple[str, str]], __exc_info: _OptExcInfo | None = ...
24+
) -> Callable[[bytes], object]: ...
1825

19-
# WSGI input streams per PEP 3333, stable
20-
class InputStream(Protocol):
21-
def read(self, size: int = ...) -> bytes: ...
22-
def readline(self, size: int = ...) -> bytes: ...
23-
def readlines(self, hint: int = ...) -> list[bytes]: ...
24-
def __iter__(self) -> Iterable[bytes]: ...
26+
WSGIEnvironment: TypeAlias = dict[str, Any] # stable
27+
WSGIApplication: TypeAlias = Callable[[WSGIEnvironment, StartResponse], Iterable[bytes]] # stable
2528

26-
# WSGI error streams per PEP 3333, stable
27-
class ErrorStream(Protocol):
28-
def flush(self) -> None: ...
29-
def write(self, s: str) -> None: ...
30-
def writelines(self, seq: list[str]) -> None: ...
29+
# WSGI input streams per PEP 3333, stable
30+
class InputStream(Protocol):
31+
def read(self, __size: int = ...) -> bytes: ...
32+
def readline(self, __size: int = ...) -> bytes: ...
33+
def readlines(self, __hint: int = ...) -> list[bytes]: ...
34+
def __iter__(self) -> Iterable[bytes]: ...
3135

32-
class _Readable(Protocol):
33-
def read(self, size: int = ...) -> bytes: ...
36+
# WSGI error streams per PEP 3333, stable
37+
class ErrorStream(Protocol):
38+
def flush(self) -> object: ...
39+
def write(self, __s: str) -> object: ...
40+
def writelines(self, __seq: list[str]) -> object: ...
3441

35-
# Optional file wrapper in wsgi.file_wrapper
36-
class FileWrapper(Protocol):
37-
def __call__(self, file: _Readable, block_size: int = ...) -> Iterable[bytes]: ...
42+
# Optional file wrapper in wsgi.file_wrapper
43+
class FileWrapper(Protocol):
44+
def __call__(self, __file: _Readable, __block_size: int = ...) -> Iterable[bytes]: ...

stdlib/typing.pyi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ if sys.version_info >= (3, 11):
2222
"ForwardRef",
2323
"Generic",
2424
"Literal",
25+
"LiteralString",
26+
"NotRequired",
2527
"Optional",
2628
"ParamSpec",
2729
"Protocol",
30+
"Required",
2831
"Tuple",
2932
"Type",
3033
"TypeVar",
@@ -84,9 +87,11 @@ if sys.version_info >= (3, 11):
8487
"assert_never",
8588
"assert_type",
8689
"cast",
90+
"clear_overloads",
8791
"final",
8892
"get_args",
8993
"get_origin",
94+
"get_overloads",
9095
"get_type_hints",
9196
"is_typeddict",
9297
"Never",
@@ -528,6 +533,9 @@ if sys.version_info >= (3, 11):
528533
Self: _SpecialForm
529534
Never: _SpecialForm = ...
530535
Unpack: _SpecialForm
536+
Required: _SpecialForm
537+
NotRequired: _SpecialForm
538+
LiteralString: _SpecialForm
531539

532540
class TypeVarTuple:
533541
__name__: str
@@ -1180,6 +1188,8 @@ if sys.version_info >= (3, 11):
11801188
def reveal_type(__obj: _T) -> _T: ...
11811189
def assert_never(__arg: Never) -> Never: ...
11821190
def assert_type(__val: _T, __typ: Any) -> _T: ...
1191+
def clear_overloads() -> None: ...
1192+
def get_overloads(func: Callable[..., object]) -> Sequence[Callable[..., object]]: ...
11831193

11841194
# Type constructors
11851195

stdlib/typing_extensions.pyi

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ from typing import ( # noqa: Y022,Y027
2222
Mapping,
2323
NewType as NewType,
2424
NoReturn as NoReturn,
25+
Sequence,
2526
Text as Text,
2627
Type as Type,
2728
TypeVar,
@@ -76,8 +77,10 @@ __all__ = [
7677
"NoReturn",
7778
"Required",
7879
"NotRequired",
80+
"clear_overloads",
7981
"get_args",
8082
"get_origin",
83+
"get_overloads",
8184
"get_type_hints",
8285
]
8386

@@ -188,10 +191,17 @@ else:
188191
# New things in 3.11
189192
if sys.version_info >= (3, 11):
190193
from typing import (
194+
LiteralString as LiteralString,
191195
Never as Never,
196+
NotRequired as NotRequired,
197+
Required as Required,
192198
Self as Self,
199+
TypeVarTuple as TypeVarTuple,
200+
Unpack as Unpack,
193201
assert_never as assert_never,
194202
assert_type as assert_type,
203+
clear_overloads as clear_overloads,
204+
get_overloads as get_overloads,
195205
reveal_type as reveal_type,
196206
)
197207
else:
@@ -200,23 +210,26 @@ else:
200210
def reveal_type(__obj: _T) -> _T: ...
201211
def assert_never(__arg: NoReturn) -> NoReturn: ...
202212
def assert_type(__val: _T, __typ: Any) -> _T: ...
213+
def clear_overloads() -> None: ...
214+
def get_overloads(func: Callable[..., object]) -> Sequence[Callable[..., object]]: ...
203215

204-
# Experimental (hopefully these will be in 3.11)
205-
Required: _SpecialForm
206-
NotRequired: _SpecialForm
207-
LiteralString: _SpecialForm
208-
Unpack: _SpecialForm
216+
Required: _SpecialForm
217+
NotRequired: _SpecialForm
218+
LiteralString: _SpecialForm
219+
Unpack: _SpecialForm
209220

210-
@final
211-
class TypeVarTuple:
212-
__name__: str
213-
def __init__(self, name: str) -> None: ...
214-
def __iter__(self) -> Any: ... # Unpack[Self]
221+
@final
222+
class TypeVarTuple:
223+
__name__: str
224+
def __init__(self, name: str) -> None: ...
225+
def __iter__(self) -> Any: ... # Unpack[Self]
215226

227+
# Experimental (hopefully these will be in 3.11)
216228
def dataclass_transform(
217229
*,
218230
eq_default: bool = ...,
219231
order_default: bool = ...,
220232
kw_only_default: bool = ...,
221-
field_descriptors: tuple[type[Any] | Callable[..., Any], ...] = ...,
233+
field_specifiers: tuple[type[Any] | Callable[..., Any], ...] = ...,
234+
**kwargs: object,
222235
) -> Callable[[_T], _T]: ...

stdlib/wsgiref/handlers.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
from _typeshed.wsgi import ErrorStream, InputStream, StartResponse, WSGIApplication, WSGIEnvironment
12
from abc import abstractmethod
23
from collections.abc import Callable, MutableMapping
34
from types import TracebackType
45
from typing import IO
56
from typing_extensions import TypeAlias
67

78
from .headers import Headers
8-
from .types import ErrorStream, InputStream, StartResponse, WSGIApplication, WSGIEnvironment
99
from .util import FileWrapper
1010

1111
__all__ = ["BaseHandler", "SimpleHandler", "BaseCGIHandler", "CGIHandler", "IISCGIHandler", "read_environ"]

stdlib/wsgiref/simple_server.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from _typeshed.wsgi import ErrorStream, StartResponse, WSGIApplication, WSGIEnvironment
12
from http.server import BaseHTTPRequestHandler, HTTPServer
23
from typing import TypeVar, overload
34

45
from .handlers import SimpleHandler
5-
from .types import ErrorStream, StartResponse, WSGIApplication, WSGIEnvironment
66

77
__all__ = ["WSGIServer", "WSGIRequestHandler", "demo_app", "make_server"]
88

stdlib/wsgiref/types.pyi

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1-
# Obsolete, use _typeshed.wsgi directly.
1+
from collections.abc import Callable, Iterable
2+
from sys import _OptExcInfo
3+
from typing import Any, Protocol
4+
from typing_extensions import TypeAlias
25

3-
from _typeshed.wsgi import *
6+
__all__ = ["StartResponse", "WSGIEnvironment", "WSGIApplication", "InputStream", "ErrorStream", "FileWrapper"]
7+
8+
class StartResponse(Protocol):
9+
def __call__(
10+
self, __status: str, __headers: list[tuple[str, str]], __exc_info: _OptExcInfo | None = ...
11+
) -> Callable[[bytes], object]: ...
12+
13+
WSGIEnvironment: TypeAlias = dict[str, Any]
14+
WSGIApplication: TypeAlias = Callable[[WSGIEnvironment, StartResponse], Iterable[bytes]]
15+
16+
class InputStream(Protocol):
17+
def read(self, __size: int = ...) -> bytes: ...
18+
def readline(self, __size: int = ...) -> bytes: ...
19+
def readlines(self, __hint: int = ...) -> list[bytes]: ...
20+
def __iter__(self) -> Iterable[bytes]: ...
21+
22+
class ErrorStream(Protocol):
23+
def flush(self) -> object: ...
24+
def write(self, __s: str) -> object: ...
25+
def writelines(self, __seq: list[str]) -> object: ...
26+
27+
class _Readable(Protocol):
28+
def read(self, __size: int = ...) -> bytes: ...
29+
# Optional: def close(self) -> object: ...
30+
31+
class FileWrapper(Protocol):
32+
def __call__(self, __file: _Readable, __block_size: int = ...) -> Iterable[bytes]: ...

stdlib/wsgiref/util.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import sys
2+
from _typeshed.wsgi import WSGIEnvironment
23
from collections.abc import Callable
34
from typing import IO, Any
45

5-
from .types import WSGIEnvironment
6-
76
__all__ = ["FileWrapper", "guess_scheme", "application_uri", "request_uri", "shift_path_info", "setup_testing_defaults"]
87

98
class FileWrapper:

tests/stubtest_allowlists/py3_common.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ weakref.ref.__call__
240240
webbrowser.UnixBrowser.remote_action # always overridden in inheriting class
241241
webbrowser.UnixBrowser.remote_action_newtab # always overridden in inheriting class
242242
webbrowser.UnixBrowser.remote_action_newwin # always overridden in inheriting class
243-
wsgiref.types # Doesn't exist, see comments in file
244243
xml.parsers.expat.expat_CAPI
245244

246245
# ==========

0 commit comments

Comments
 (0)