Skip to content

Commit 3f5409c

Browse files
Merge branch 'master' into patch-9
2 parents 59740e2 + c71fef0 commit 3f5409c

27 files changed

+1022
-1008
lines changed

mypy/cache.py

Lines changed: 14 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,22 @@
11
from __future__ import annotations
22

33
from collections.abc import Sequence
4-
from typing import TYPE_CHECKING, Final
4+
from typing import Final
55

66
from mypy_extensions import u8
7-
8-
try:
9-
from native_internal import (
10-
Buffer as Buffer,
11-
read_bool as read_bool,
12-
read_float as read_float,
13-
read_int as read_int,
14-
read_str as read_str,
15-
read_tag as read_tag,
16-
write_bool as write_bool,
17-
write_float as write_float,
18-
write_int as write_int,
19-
write_str as write_str,
20-
write_tag as write_tag,
21-
)
22-
except ImportError:
23-
# TODO: temporary, remove this after we publish mypy-native on PyPI.
24-
if not TYPE_CHECKING:
25-
26-
class Buffer:
27-
def __init__(self, source: bytes = b"") -> None:
28-
raise NotImplementedError
29-
30-
def getvalue(self) -> bytes:
31-
raise NotImplementedError
32-
33-
def read_int(data: Buffer) -> int:
34-
raise NotImplementedError
35-
36-
def write_int(data: Buffer, value: int) -> None:
37-
raise NotImplementedError
38-
39-
def read_tag(data: Buffer) -> u8:
40-
raise NotImplementedError
41-
42-
def write_tag(data: Buffer, value: u8) -> None:
43-
raise NotImplementedError
44-
45-
def read_str(data: Buffer) -> str:
46-
raise NotImplementedError
47-
48-
def write_str(data: Buffer, value: str) -> None:
49-
raise NotImplementedError
50-
51-
def read_bool(data: Buffer) -> bool:
52-
raise NotImplementedError
53-
54-
def write_bool(data: Buffer, value: bool) -> None:
55-
raise NotImplementedError
56-
57-
def read_float(data: Buffer) -> float:
58-
raise NotImplementedError
59-
60-
def write_float(data: Buffer, value: float) -> None:
61-
raise NotImplementedError
62-
7+
from native_internal import (
8+
Buffer as Buffer,
9+
read_bool as read_bool,
10+
read_float as read_float,
11+
read_int as read_int,
12+
read_str as read_str,
13+
read_tag as read_tag,
14+
write_bool as write_bool,
15+
write_float as write_float,
16+
write_int as write_int,
17+
write_str as write_str,
18+
write_tag as write_tag,
19+
)
6320

6421
# Always use this type alias to refer to type tags.
6522
Tag = u8

mypy/checkexpr.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from mypy.checker_shared import ExpressionCheckerSharedApi
1919
from mypy.checkmember import analyze_member_access, has_operator
2020
from mypy.checkstrformat import StringFormatterChecker
21+
from mypy.constant_fold import constant_fold_expr
2122
from mypy.erasetype import erase_type, remove_instance_last_known_values, replace_meta_vars
2223
from mypy.errors import ErrorInfo, ErrorWatcher, report_internal_error
2324
from mypy.expandtype import (
@@ -656,11 +657,12 @@ def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) ->
656657
return ret_type
657658

658659
def check_str_format_call(self, e: CallExpr) -> None:
659-
"""More precise type checking for str.format() calls on literals."""
660+
"""More precise type checking for str.format() calls on literals and folded constants."""
660661
assert isinstance(e.callee, MemberExpr)
661662
format_value = None
662-
if isinstance(e.callee.expr, StrExpr):
663-
format_value = e.callee.expr.value
663+
folded_callee_expr = constant_fold_expr(e.callee.expr, "<unused>")
664+
if isinstance(folded_callee_expr, str):
665+
format_value = folded_callee_expr
664666
elif self.chk.has_type(e.callee.expr):
665667
typ = get_proper_type(self.chk.lookup_type(e.callee.expr))
666668
if (

mypy/semanal_shared.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ def calculate_tuple_fallback(typ: TupleType) -> None:
303303
):
304304
items.append(unpacked_type.args[0])
305305
else:
306-
raise NotImplementedError
306+
# This is called before semanal_typeargs.py fixes broken unpacks,
307+
# where the error should also be generated.
308+
items.append(AnyType(TypeOfAny.from_error))
307309
else:
308310
items.append(item)
309311
fallback.args = (make_simplified_union(items),)

mypy/typeanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ def try_analyze_special_unbound_type(self, t: UnboundType, fullname: str) -> Typ
634634
)
635635
elif fullname == "typing.Union":
636636
items = self.anal_array(t.args)
637-
return UnionType.make_union(items)
637+
return UnionType.make_union(items, line=t.line, column=t.column)
638638
elif fullname == "typing.Optional":
639639
if len(t.args) != 1:
640640
self.fail(

mypy/typeshed/stdlib/_collections_abc.pyi

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import sys
22
from abc import abstractmethod
33
from types import MappingProxyType
4-
from typing import ( # noqa: Y022,Y038,UP035
4+
from typing import ( # noqa: Y022,Y038,UP035,Y057
55
AbstractSet as Set,
66
AsyncGenerator as AsyncGenerator,
77
AsyncIterable as AsyncIterable,
88
AsyncIterator as AsyncIterator,
99
Awaitable as Awaitable,
10+
ByteString as ByteString,
1011
Callable as Callable,
1112
ClassVar,
1213
Collection as Collection,
@@ -59,12 +60,8 @@ __all__ = [
5960
"ValuesView",
6061
"Sequence",
6162
"MutableSequence",
63+
"ByteString",
6264
]
63-
if sys.version_info < (3, 14):
64-
from typing import ByteString as ByteString # noqa: Y057,UP035
65-
66-
__all__ += ["ByteString"]
67-
6865
if sys.version_info >= (3, 12):
6966
__all__ += ["Buffer"]
7067

mypy/typeshed/stdlib/_frozen_importlib.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __import__(
1313
name: str,
1414
globals: Mapping[str, object] | None = None,
1515
locals: Mapping[str, object] | None = None,
16-
fromlist: Sequence[str] = (),
16+
fromlist: Sequence[str] | None = (),
1717
level: int = 0,
1818
) -> ModuleType: ...
1919
def spec_from_loader(

mypy/typeshed/stdlib/_tkinter.pyi

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,34 +54,34 @@ _TkinterTraceFunc: TypeAlias = Callable[[tuple[str, ...]], object]
5454
@final
5555
class TkappType:
5656
# Please keep in sync with tkinter.Tk
57-
def adderrorinfo(self, msg, /): ...
57+
def adderrorinfo(self, msg: str, /): ...
5858
def call(self, command: Any, /, *args: Any) -> Any: ...
59-
def createcommand(self, name, func, /): ...
59+
def createcommand(self, name: str, func, /): ...
6060
if sys.platform != "win32":
61-
def createfilehandler(self, file, mask, func, /): ...
62-
def deletefilehandler(self, file, /): ...
61+
def createfilehandler(self, file, mask: int, func, /): ...
62+
def deletefilehandler(self, file, /) -> None: ...
6363

64-
def createtimerhandler(self, milliseconds, func, /): ...
65-
def deletecommand(self, name, /): ...
64+
def createtimerhandler(self, milliseconds: int, func, /): ...
65+
def deletecommand(self, name: str, /): ...
6666
def dooneevent(self, flags: int = 0, /): ...
6767
def eval(self, script: str, /) -> str: ...
68-
def evalfile(self, fileName, /): ...
69-
def exprboolean(self, s, /): ...
70-
def exprdouble(self, s, /): ...
71-
def exprlong(self, s, /): ...
72-
def exprstring(self, s, /): ...
73-
def getboolean(self, arg, /): ...
74-
def getdouble(self, arg, /): ...
75-
def getint(self, arg, /): ...
68+
def evalfile(self, fileName: str, /): ...
69+
def exprboolean(self, s: str, /): ...
70+
def exprdouble(self, s: str, /): ...
71+
def exprlong(self, s: str, /): ...
72+
def exprstring(self, s: str, /): ...
73+
def getboolean(self, arg, /) -> bool: ...
74+
def getdouble(self, arg, /) -> float: ...
75+
def getint(self, arg, /) -> int: ...
7676
def getvar(self, *args, **kwargs): ...
7777
def globalgetvar(self, *args, **kwargs): ...
7878
def globalsetvar(self, *args, **kwargs): ...
7979
def globalunsetvar(self, *args, **kwargs): ...
8080
def interpaddr(self) -> int: ...
8181
def loadtk(self) -> None: ...
82-
def mainloop(self, threshold: int = 0, /): ...
83-
def quit(self): ...
84-
def record(self, script, /): ...
82+
def mainloop(self, threshold: int = 0, /) -> None: ...
83+
def quit(self) -> None: ...
84+
def record(self, script: str, /): ...
8585
def setvar(self, *ags, **kwargs): ...
8686
if sys.version_info < (3, 11):
8787
@deprecated("Deprecated since Python 3.9; removed in Python 3.11. Use `splitlist()` instead.")
@@ -90,7 +90,7 @@ class TkappType:
9090
def splitlist(self, arg, /): ...
9191
def unsetvar(self, *args, **kwargs): ...
9292
def wantobjects(self, *args, **kwargs): ...
93-
def willdispatch(self): ...
93+
def willdispatch(self) -> None: ...
9494
if sys.version_info >= (3, 12):
9595
def gettrace(self, /) -> _TkinterTraceFunc | None: ...
9696
def settrace(self, func: _TkinterTraceFunc | None, /) -> None: ...
@@ -140,5 +140,5 @@ else:
140140
/,
141141
): ...
142142

143-
def getbusywaitinterval(): ...
144-
def setbusywaitinterval(new_val, /): ...
143+
def getbusywaitinterval() -> int: ...
144+
def setbusywaitinterval(new_val: int, /) -> None: ...

mypy/typeshed/stdlib/asyncio/tools.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from collections.abc import Iterable
23
from enum import Enum
34
from typing import NamedTuple, SupportsIndex, type_check_only
@@ -37,5 +38,9 @@ class CycleFoundException(Exception):
3738
def get_all_awaited_by(pid: SupportsIndex) -> list[_AwaitedInfo]: ...
3839
def build_async_tree(result: Iterable[_AwaitedInfo], task_emoji: str = "(T)", cor_emoji: str = "") -> list[list[str]]: ...
3940
def build_task_table(result: Iterable[_AwaitedInfo]) -> list[list[int | str]]: ...
41+
42+
if sys.version_info >= (3, 14):
43+
def exit_with_permission_help_text() -> None: ...
44+
4045
def display_awaited_by_tasks_table(pid: SupportsIndex) -> None: ...
4146
def display_awaited_by_tasks_tree(pid: SupportsIndex) -> None: ...

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,7 @@ def __import__(
19171917
name: str,
19181918
globals: Mapping[str, object] | None = None,
19191919
locals: Mapping[str, object] | None = None,
1920-
fromlist: Sequence[str] = (),
1920+
fromlist: Sequence[str] | None = (),
19211921
level: int = 0,
19221922
) -> types.ModuleType: ...
19231923
def __build_class__(func: Callable[[], CellType | Any], name: str, /, *bases: Any, metaclass: Any = ..., **kwds: Any) -> Any: ...

mypy/typeshed/stdlib/concurrent/interpreters/_queues.pyi

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,30 @@ if sys.version_info >= (3, 13): # needed to satisfy pyright checks for Python <
4545
def empty(self) -> bool: ...
4646
def full(self) -> bool: ...
4747
def qsize(self) -> int: ...
48-
def put(
49-
self,
50-
obj: object,
51-
timeout: SupportsIndex | None = None,
52-
*,
53-
unbounditems: _AnyUnbound | None = None,
54-
_delay: float = 0.01,
55-
) -> None: ...
48+
if sys.version_info >= (3, 14):
49+
def put(
50+
self,
51+
obj: object,
52+
block: bool = True,
53+
timeout: SupportsIndex | None = None,
54+
*,
55+
unbounditems: _AnyUnbound | None = None,
56+
_delay: float = 0.01,
57+
) -> None: ...
58+
else:
59+
def put(
60+
self,
61+
obj: object,
62+
timeout: SupportsIndex | None = None,
63+
*,
64+
unbounditems: _AnyUnbound | None = None,
65+
_delay: float = 0.01,
66+
) -> None: ...
67+
5668
def put_nowait(self, obj: object, *, unbounditems: _AnyUnbound | None = None) -> None: ...
57-
def get(self, timeout: SupportsIndex | None = None, *, _delay: float = 0.01) -> object: ...
69+
if sys.version_info >= (3, 14):
70+
def get(self, block: bool = True, timeout: SupportsIndex | None = None, *, _delay: float = 0.01) -> object: ...
71+
else:
72+
def get(self, timeout: SupportsIndex | None = None, *, _delay: float = 0.01) -> object: ...
73+
5874
def get_nowait(self) -> object: ...

0 commit comments

Comments
 (0)