Skip to content

Commit a379621

Browse files
Merge branch 'master' into fix-isinstance-native-interpreted-subclass
2 parents 9dbc600 + 1b6ebb1 commit a379621

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+6154
-134
lines changed

LICENSE

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,38 @@ FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
227227
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
228228
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
229229
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
230+
231+
= = = = =
232+
233+
Files under lib-rt/base64 are licensed under the following license.
234+
235+
= = = = =
236+
237+
Copyright (c) 2005-2007, Nick Galbreath
238+
Copyright (c) 2015-2018, Wojciech Muła
239+
Copyright (c) 2016-2017, Matthieu Darbois
240+
Copyright (c) 2013-2022, Alfred Klomp
241+
All rights reserved.
242+
243+
Redistribution and use in source and binary forms, with or without
244+
modification, are permitted provided that the following conditions are
245+
met:
246+
247+
- Redistributions of source code must retain the above copyright notice,
248+
this list of conditions and the following disclaimer.
249+
250+
- Redistributions in binary form must reproduce the above copyright
251+
notice, this list of conditions and the following disclaimer in the
252+
documentation and/or other materials provided with the distribution.
253+
254+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
255+
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
256+
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
257+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
258+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
259+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
260+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
261+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
262+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
263+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
264+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

mypy/exprtotype.py

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ def expr_to_unanalyzed_type(
100100
else:
101101
raise TypeTranslationError()
102102
elif isinstance(expr, IndexExpr):
103-
base = expr_to_unanalyzed_type(expr.base, options, allow_new_syntax, expr)
103+
base = expr_to_unanalyzed_type(
104+
expr.base, options, allow_new_syntax, expr, lookup_qualified=lookup_qualified
105+
)
104106
if isinstance(base, UnboundType):
105107
if base.args:
106108
raise TypeTranslationError()
@@ -124,9 +126,18 @@ def expr_to_unanalyzed_type(
124126
# TODO: this is not the optimal solution as we are basically getting rid
125127
# of the Annotation definition and only returning the type information,
126128
# losing all the annotations.
127-
return expr_to_unanalyzed_type(args[0], options, allow_new_syntax, expr)
129+
return expr_to_unanalyzed_type(
130+
args[0], options, allow_new_syntax, expr, lookup_qualified=lookup_qualified
131+
)
128132
base.args = tuple(
129-
expr_to_unanalyzed_type(arg, options, allow_new_syntax, expr, allow_unpack=True)
133+
expr_to_unanalyzed_type(
134+
arg,
135+
options,
136+
allow_new_syntax,
137+
expr,
138+
allow_unpack=True,
139+
lookup_qualified=lookup_qualified,
140+
)
130141
for arg in args
131142
)
132143
if not base.args:
@@ -141,8 +152,12 @@ def expr_to_unanalyzed_type(
141152
):
142153
return UnionType(
143154
[
144-
expr_to_unanalyzed_type(expr.left, options, allow_new_syntax),
145-
expr_to_unanalyzed_type(expr.right, options, allow_new_syntax),
155+
expr_to_unanalyzed_type(
156+
expr.left, options, allow_new_syntax, lookup_qualified=lookup_qualified
157+
),
158+
expr_to_unanalyzed_type(
159+
expr.right, options, allow_new_syntax, lookup_qualified=lookup_qualified
160+
),
146161
],
147162
uses_pep604_syntax=True,
148163
)
@@ -178,12 +193,16 @@ def expr_to_unanalyzed_type(
178193
if typ is not default_type:
179194
# Two types
180195
raise TypeTranslationError()
181-
typ = expr_to_unanalyzed_type(arg, options, allow_new_syntax, expr)
196+
typ = expr_to_unanalyzed_type(
197+
arg, options, allow_new_syntax, expr, lookup_qualified=lookup_qualified
198+
)
182199
continue
183200
else:
184201
raise TypeTranslationError()
185202
elif i == 0:
186-
typ = expr_to_unanalyzed_type(arg, options, allow_new_syntax, expr)
203+
typ = expr_to_unanalyzed_type(
204+
arg, options, allow_new_syntax, expr, lookup_qualified=lookup_qualified
205+
)
187206
elif i == 1:
188207
name = _extract_argument_name(arg)
189208
else:
@@ -192,7 +211,14 @@ def expr_to_unanalyzed_type(
192211
elif isinstance(expr, ListExpr):
193212
return TypeList(
194213
[
195-
expr_to_unanalyzed_type(t, options, allow_new_syntax, expr, allow_unpack=True)
214+
expr_to_unanalyzed_type(
215+
t,
216+
options,
217+
allow_new_syntax,
218+
expr,
219+
allow_unpack=True,
220+
lookup_qualified=lookup_qualified,
221+
)
196222
for t in expr.items
197223
],
198224
line=expr.line,
@@ -203,7 +229,9 @@ def expr_to_unanalyzed_type(
203229
elif isinstance(expr, BytesExpr):
204230
return parse_type_string(expr.value, "builtins.bytes", expr.line, expr.column)
205231
elif isinstance(expr, UnaryExpr):
206-
typ = expr_to_unanalyzed_type(expr.expr, options, allow_new_syntax)
232+
typ = expr_to_unanalyzed_type(
233+
expr.expr, options, allow_new_syntax, lookup_qualified=lookup_qualified
234+
)
207235
if isinstance(typ, RawExpressionType):
208236
if isinstance(typ.literal_value, int):
209237
if expr.op == "-":
@@ -225,7 +253,10 @@ def expr_to_unanalyzed_type(
225253
return EllipsisType(expr.line)
226254
elif allow_unpack and isinstance(expr, StarExpr):
227255
return UnpackType(
228-
expr_to_unanalyzed_type(expr.expr, options, allow_new_syntax), from_star_syntax=True
256+
expr_to_unanalyzed_type(
257+
expr.expr, options, allow_new_syntax, lookup_qualified=lookup_qualified
258+
),
259+
from_star_syntax=True,
229260
)
230261
elif isinstance(expr, DictExpr):
231262
if not expr.items:
@@ -236,12 +267,18 @@ def expr_to_unanalyzed_type(
236267
if not isinstance(item_name, StrExpr):
237268
if item_name is None:
238269
extra_items_from.append(
239-
expr_to_unanalyzed_type(value, options, allow_new_syntax, expr)
270+
expr_to_unanalyzed_type(
271+
value,
272+
options,
273+
allow_new_syntax,
274+
expr,
275+
lookup_qualified=lookup_qualified,
276+
)
240277
)
241278
continue
242279
raise TypeTranslationError()
243280
items[item_name.value] = expr_to_unanalyzed_type(
244-
value, options, allow_new_syntax, expr
281+
value, options, allow_new_syntax, expr, lookup_qualified=lookup_qualified
245282
)
246283
result = TypedDictType(
247284
items, set(), set(), Instance(MISSING_FALLBACK, ()), expr.line, expr.column

mypy/typeshed/stdlib/_compression.pyi

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# _compression is replaced by compression._common._streams on Python 3.14+ (PEP-784)
22

3-
from _typeshed import Incomplete, WriteableBuffer
3+
from _typeshed import ReadableBuffer, WriteableBuffer
44
from collections.abc import Callable
55
from io import DEFAULT_BUFFER_SIZE, BufferedIOBase, RawIOBase
66
from typing import Any, Protocol, type_check_only
@@ -13,13 +13,24 @@ class _Reader(Protocol):
1313
def seekable(self) -> bool: ...
1414
def seek(self, n: int, /) -> Any: ...
1515

16+
@type_check_only
17+
class _Decompressor(Protocol):
18+
def decompress(self, data: ReadableBuffer, /, max_length: int = ...) -> bytes: ...
19+
@property
20+
def unused_data(self) -> bytes: ...
21+
@property
22+
def eof(self) -> bool: ...
23+
# `zlib._Decompress` does not have next property, but `DecompressReader` calls it:
24+
# @property
25+
# def needs_input(self) -> bool: ...
26+
1627
class BaseStream(BufferedIOBase): ...
1728

1829
class DecompressReader(RawIOBase):
1930
def __init__(
2031
self,
2132
fp: _Reader,
22-
decomp_factory: Callable[..., Incomplete],
33+
decomp_factory: Callable[..., _Decompressor],
2334
trailing_error: type[Exception] | tuple[type[Exception], ...] = (),
2435
**decomp_args: Any, # These are passed to decomp_factory.
2536
) -> None: ...

mypy/typeshed/stdlib/asyncio/protocols.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class BaseProtocol:
1414

1515
class Protocol(BaseProtocol):
1616
# Need annotation or mypy will complain about 'Cannot determine type of "__slots__" in base class'
17-
__slots__: tuple[()] = ()
17+
__slots__: tuple[str, ...] = ()
1818
def data_received(self, data: bytes) -> None: ...
1919
def eof_received(self) -> bool | None: ...
2020

@@ -35,7 +35,7 @@ class DatagramProtocol(BaseProtocol):
3535
def error_received(self, exc: Exception) -> None: ...
3636

3737
class SubprocessProtocol(BaseProtocol):
38-
__slots__: tuple[()] = ()
38+
__slots__: tuple[str, ...] = ()
3939
def pipe_data_received(self, fd: int, data: bytes) -> None: ...
4040
def pipe_connection_lost(self, fd: int, exc: Exception | None) -> None: ...
4141
def process_exited(self) -> None: ...

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ from typing import ( # noqa: Y022,UP035
4242
Any,
4343
BinaryIO,
4444
ClassVar,
45+
Final,
4546
Generic,
4647
Mapping,
4748
MutableMapping,
@@ -188,8 +189,9 @@ class type:
188189
__bases__: tuple[type, ...]
189190
@property
190191
def __basicsize__(self) -> int: ...
191-
@property
192-
def __dict__(self) -> types.MappingProxyType[str, Any]: ... # type: ignore[override]
192+
# type.__dict__ is read-only at runtime, but that can't be expressed currently.
193+
# See https://github.com/python/typeshed/issues/11033 for a discussion.
194+
__dict__: Final[types.MappingProxyType[str, Any]] # type: ignore[assignment]
193195
@property
194196
def __dictoffset__(self) -> int: ...
195197
@property
@@ -1267,13 +1269,6 @@ class property:
12671269
def __set__(self, instance: Any, value: Any, /) -> None: ...
12681270
def __delete__(self, instance: Any, /) -> None: ...
12691271

1270-
@final
1271-
@type_check_only
1272-
class _NotImplementedType(Any):
1273-
__call__: None
1274-
1275-
NotImplemented: _NotImplementedType
1276-
12771272
def abs(x: SupportsAbs[_T], /) -> _T: ...
12781273
def all(iterable: Iterable[object], /) -> bool: ...
12791274
def any(iterable: Iterable[object], /) -> bool: ...
@@ -1932,14 +1927,14 @@ def __import__(
19321927
def __build_class__(func: Callable[[], CellType | Any], name: str, /, *bases: Any, metaclass: Any = ..., **kwds: Any) -> Any: ...
19331928

19341929
if sys.version_info >= (3, 10):
1935-
from types import EllipsisType
1930+
from types import EllipsisType, NotImplementedType
19361931

19371932
# Backwards compatibility hack for folks who relied on the ellipsis type
19381933
# existing in typeshed in Python 3.9 and earlier.
19391934
ellipsis = EllipsisType
19401935

19411936
Ellipsis: EllipsisType
1942-
1937+
NotImplemented: NotImplementedType
19431938
else:
19441939
# Actually the type of Ellipsis is <type 'ellipsis'>, but since it's
19451940
# not exposed anywhere under that name, we make it private here.
@@ -1949,6 +1944,12 @@ else:
19491944

19501945
Ellipsis: ellipsis
19511946

1947+
@final
1948+
@type_check_only
1949+
class _NotImplementedType(Any): ...
1950+
1951+
NotImplemented: _NotImplementedType
1952+
19521953
@disjoint_base
19531954
class BaseException:
19541955
args: tuple[Any, ...]

mypy/typeshed/stdlib/compression/_common/_streams.pyi

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from _typeshed import Incomplete, WriteableBuffer
1+
from _typeshed import ReadableBuffer, WriteableBuffer
22
from collections.abc import Callable
33
from io import DEFAULT_BUFFER_SIZE, BufferedIOBase, RawIOBase
44
from typing import Any, Protocol, type_check_only
@@ -11,13 +11,24 @@ class _Reader(Protocol):
1111
def seekable(self) -> bool: ...
1212
def seek(self, n: int, /) -> Any: ...
1313

14+
@type_check_only
15+
class _Decompressor(Protocol):
16+
def decompress(self, data: ReadableBuffer, /, max_length: int = ...) -> bytes: ...
17+
@property
18+
def unused_data(self) -> bytes: ...
19+
@property
20+
def eof(self) -> bool: ...
21+
# `zlib._Decompress` does not have next property, but `DecompressReader` calls it:
22+
# @property
23+
# def needs_input(self) -> bool: ...
24+
1425
class BaseStream(BufferedIOBase): ...
1526

1627
class DecompressReader(RawIOBase):
1728
def __init__(
1829
self,
1930
fp: _Reader,
20-
decomp_factory: Callable[..., Incomplete], # Consider backporting changes to _compression
31+
decomp_factory: Callable[..., _Decompressor], # Consider backporting changes to _compression
2132
trailing_error: type[Exception] | tuple[type[Exception], ...] = (),
2233
**decomp_args: Any, # These are passed to decomp_factory.
2334
) -> None: ...

mypy/typeshed/stdlib/html/parser.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class HTMLParser(ParserBase):
99
# Added in Python 3.9.23, 3.10.18, 3.11.13, 3.12.11, 3.13.6
1010
RCDATA_CONTENT_ELEMENTS: Final[tuple[str, ...]]
1111

12-
def __init__(self, *, convert_charrefs: bool = True) -> None: ...
12+
# `scripting` parameter added in Python 3.9.25, 3.10.20, 3.11.15, 3.12.13, 3.13.10, 3.14.1
13+
def __init__(self, *, convert_charrefs: bool = True, scripting: bool = False) -> None: ...
1314
def feed(self, data: str) -> None: ...
1415
def close(self) -> None: ...
1516
def get_starttag_text(self) -> str | None: ...

mypy/typeshed/stdlib/http/client.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class HTTPResponse(io.BufferedIOBase, BinaryIO): # type: ignore[misc] # incomp
166166
def begin(self) -> None: ...
167167

168168
class HTTPConnection:
169+
blocksize: int
169170
auto_open: int # undocumented
170171
debuglevel: int
171172
default_port: int # undocumented

mypy/typeshed/stdlib/imaplib.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class IMAP4:
2626
class error(Exception): ...
2727
class abort(error): ...
2828
class readonly(abort): ...
29+
utf8_enabled: bool
2930
mustquote: Pattern[str]
3031
debug: int
3132
state: str

mypy/typeshed/stdlib/importlib/util.pyi

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ from importlib._bootstrap_external import (
1212
spec_from_file_location as spec_from_file_location,
1313
)
1414
from importlib.abc import Loader
15-
from typing_extensions import ParamSpec, deprecated
15+
from types import TracebackType
16+
from typing import Literal
17+
from typing_extensions import ParamSpec, Self, deprecated
1618

1719
_P = ParamSpec("_P")
1820

@@ -44,6 +46,18 @@ class LazyLoader(Loader):
4446

4547
def source_hash(source_bytes: ReadableBuffer) -> bytes: ...
4648

49+
if sys.version_info >= (3, 12):
50+
class _incompatible_extension_module_restrictions:
51+
def __init__(self, *, disable_check: bool) -> None: ...
52+
disable_check: bool
53+
old: Literal[-1, 0, 1] # exists only while entered
54+
def __enter__(self) -> Self: ...
55+
def __exit__(
56+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
57+
) -> None: ...
58+
@property
59+
def override(self) -> Literal[-1, 1]: ... # undocumented
60+
4761
if sys.version_info >= (3, 14):
4862
__all__ = [
4963
"LazyLoader",

0 commit comments

Comments
 (0)