Skip to content

Commit 82d15f5

Browse files
committed
Merge remote-tracking branch 'upstream/master' into match-sequence-unreachable
2 parents 0a7b920 + b38413d commit 82d15f5

File tree

124 files changed

+4055
-902
lines changed

Some content is hidden

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

124 files changed

+4055
-902
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ repos:
4141
# actionlint has a shellcheck integration which extracts shell scripts in `run:` steps from GitHub Actions
4242
# and checks these with shellcheck. This is arguably its most useful feature,
4343
# but the integration only works if shellcheck is installed
44-
- "github.com/wasilibs/go-shellcheck/cmd/shellcheck@v0.10.0"
44+
- "github.com/wasilibs/go-shellcheck/cmd/shellcheck@v0.11.1"
4545
- repo: https://github.com/woodruffw/zizmor-pre-commit
4646
rev: v1.5.2
4747
hooks:

docs/source/common_issues.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ This example demonstrates both safe and unsafe overrides:
731731
732732
class NarrowerReturn(A):
733733
# A more specific return type is fine
734-
def test(self, t: Sequence[int]) -> List[str]: # OK
734+
def test(self, t: Sequence[int]) -> list[str]: # OK
735735
...
736736
737737
class GeneralizedReturn(A):
@@ -746,7 +746,7 @@ not necessary:
746746
.. code-block:: python
747747
748748
class NarrowerArgument(A):
749-
def test(self, t: List[int]) -> Sequence[str]: # type: ignore[override]
749+
def test(self, t: list[int]) -> Sequence[str]: # type: ignore[override]
750750
...
751751
752752
.. _unreachable:

docs/source/error_code_list2.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,3 +676,26 @@ Example:
676676
print("red")
677677
case _:
678678
print("other")
679+
680+
.. _code-untyped-decorator:
681+
682+
Error if an untyped decorator makes a typed function effectively untyped [untyped-decorator]
683+
--------------------------------------------------------------------------------------------
684+
685+
If enabled with :option:`--disallow-untyped-decorators <mypy --disallow-untyped-decorators>`
686+
mypy generates an error if a typed function is wrapped by an untyped decorator
687+
(as this would effectively remove the benefits of typing the function).
688+
689+
Example:
690+
691+
.. code-block:: python
692+
693+
def printing_decorator(func):
694+
def wrapper(*args, **kwds):
695+
print("Calling", func)
696+
return func(*args, **kwds)
697+
return wrapper
698+
# A decorated function.
699+
@printing_decorator # E: Untyped decorator makes function "add_forty_two" untyped [untyped-decorator]
700+
def add_forty_two(value: int) -> int:
701+
return value + 42

docs/source/generics.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ This example correctly uses a covariant type variable:
11651165
11661166
See :ref:`variance-of-generics` for more about variance.
11671167

1168-
Generic protocols can also be recursive. Example (Python 3.12 synta):
1168+
Generic protocols can also be recursive. Example (Python 3.12 syntax):
11691169

11701170
.. code-block:: python
11711171

docs/source/stubtest.rst

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,75 @@ to mypy build errors". In this case, you will need to mitigate those errors
9999
before stubtest will run. Despite potential overlap in errors here, stubtest is
100100
not intended as a substitute for running mypy directly.
101101

102+
Allowlist
103+
*********
104+
102105
If you wish to ignore some of stubtest's complaints, stubtest supports a
103-
pretty handy allowlist system.
106+
pretty handy :option:`--allowlist` system.
107+
108+
Let's say that you have this python module called ``ex``:
109+
110+
.. code-block:: python
111+
112+
try:
113+
import optional_expensive_dep
114+
except ImportError:
115+
optional_expensive_dep = None
116+
117+
first = 1
118+
if optional_expensive_dep:
119+
second = 2
120+
121+
Let's say that you can't install ``optional_expensive_dep`` in CI for some reason,
122+
but you still want to include ``second: int`` in the stub file:
123+
124+
.. code-block:: python
125+
126+
first: int
127+
second: int
128+
129+
In this case stubtest will correctly complain:
130+
131+
.. code-block:: shell
132+
133+
error: ex.second is not present at runtime
134+
Stub: in file /.../ex.pyi:2
135+
builtins.int
136+
Runtime:
137+
MISSING
138+
139+
Found 1 error (checked 1 module)
140+
141+
To fix this, you can add an ``allowlist`` entry:
142+
143+
.. code-block:: ini
144+
145+
# Allowlist entries in `allowlist.txt` file:
146+
147+
# Does not exist if `optional_expensive_dep` is not installed:
148+
ex.second
149+
150+
And now when running stubtest with ``--allowlist=allowlist.txt``,
151+
no errors will be generated anymore.
152+
153+
Allowlists also support regular expressions,
154+
which can be useful to ignore many similar errors at once.
155+
They can also be useful for suppressing stubtest errors that occur sometimes,
156+
but not on every CI run. For example, if some CI workers have
157+
``optional_expensive_dep`` installed, stubtest might complain with this message
158+
on those workers if you had the ``ex.second`` allowlist entry:
159+
160+
.. code-block:: ini
161+
162+
note: unused allowlist entry ex.second
163+
Found 1 error (checked 1 module)
164+
165+
Changing ``ex.second`` to be ``(ex\.second)?`` will make this error optional,
166+
meaning that stubtest will pass whether or not a CI runner
167+
has``optional_expensive_dep`` installed.
168+
169+
CLI
170+
***
104171

105172
The rest of this section documents the command line interface of stubtest.
106173

@@ -119,15 +186,15 @@ The rest of this section documents the command line interface of stubtest.
119186
.. option:: --allowlist FILE
120187

121188
Use file as an allowlist. Can be passed multiple times to combine multiple
122-
allowlists. Allowlists can be created with --generate-allowlist. Allowlists
123-
support regular expressions.
189+
allowlists. Allowlists can be created with :option:`--generate-allowlist`.
190+
Allowlists support regular expressions.
124191

125192
The presence of an entry in the allowlist means stubtest will not generate
126193
any errors for the corresponding definition.
127194

128195
.. option:: --generate-allowlist
129196

130-
Print an allowlist (to stdout) to be used with --allowlist
197+
Print an allowlist (to stdout) to be used with :option:`--allowlist`.
131198

132199
When introducing stubtest to an existing project, this is an easy way to
133200
silence all existing errors.
@@ -141,17 +208,17 @@ The rest of this section documents the command line interface of stubtest.
141208

142209
Note if an allowlist entry is a regex that matches the empty string,
143210
stubtest will never consider it unused. For example, to get
144-
`--ignore-unused-allowlist` behaviour for a single allowlist entry like
211+
``--ignore-unused-allowlist`` behaviour for a single allowlist entry like
145212
``foo.bar`` you could add an allowlist entry ``(foo\.bar)?``.
146213
This can be useful when an error only occurs on a specific platform.
147214

148215
.. option:: --mypy-config-file FILE
149216

150-
Use specified mypy config file to determine mypy plugins and mypy path
217+
Use specified mypy config *file* to determine mypy plugins and mypy path
151218

152219
.. option:: --custom-typeshed-dir DIR
153220

154-
Use the custom typeshed in DIR
221+
Use the custom typeshed in *DIR*
155222

156223
.. option:: --check-typeshed
157224

misc/typeshed_patches/0001-Remove-use-of-LiteralString-in-builtins-13743.patch

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 805d7fc06a8bee350959512e0908a18a87b7f8c2 Mon Sep 17 00:00:00 2001
1+
From 3229a6066cff3d80d6cb923322c2d42a300d0be3 Mon Sep 17 00:00:00 2001
22
From: Shantanu <[email protected]>
33
Date: Mon, 26 Sep 2022 12:55:07 -0700
44
Subject: [PATCH] Remove use of LiteralString in builtins (#13743)
@@ -8,7 +8,7 @@ Subject: [PATCH] Remove use of LiteralString in builtins (#13743)
88
1 file changed, 1 insertion(+), 99 deletions(-)
99

1010
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
11-
index c7ab95482..3e93da36e 100644
11+
index 969d16876..044e264d2 100644
1212
--- a/mypy/typeshed/stdlib/builtins.pyi
1313
+++ b/mypy/typeshed/stdlib/builtins.pyi
1414
@@ -63,7 +63,6 @@ from typing import ( # noqa: Y022,UP035
@@ -19,10 +19,10 @@ index c7ab95482..3e93da36e 100644
1919
ParamSpec,
2020
Self,
2121
TypeAlias,
22-
@@ -468,31 +467,16 @@ class str(Sequence[str]):
23-
def __new__(cls, object: object = ...) -> Self: ...
22+
@@ -480,31 +479,16 @@ class str(Sequence[str]):
23+
def __new__(cls, object: object = "") -> Self: ...
2424
@overload
25-
def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ...
25+
def __new__(cls, object: ReadableBuffer, encoding: str = "utf-8", errors: str = "strict") -> Self: ...
2626
- @overload
2727
- def capitalize(self: LiteralString) -> LiteralString: ...
2828
- @overload
@@ -35,23 +35,23 @@ index c7ab95482..3e93da36e 100644
3535
- def center(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
3636
- @overload
3737
def center(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
38-
def count(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
38+
def count(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
3939
def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
4040
def endswith(
41-
self, suffix: str | tuple[str, ...], start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
41+
self, suffix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
4242
) -> bool: ...
4343
- @overload
4444
- def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
4545
- @overload
4646
def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
47-
def find(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
47+
def find(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
4848
- @overload
4949
- def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
5050
- @overload
5151
def format(self, *args: object, **kwargs: object) -> str: ...
5252
def format_map(self, mapping: _FormatMapMapping, /) -> str: ...
53-
def index(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
54-
@@ -508,98 +492,34 @@ class str(Sequence[str]):
53+
def index(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
54+
@@ -520,98 +504,34 @@ class str(Sequence[str]):
5555
def isspace(self) -> bool: ...
5656
def istitle(self) -> bool: ...
5757
def isupper(self) -> bool: ...
@@ -98,8 +98,8 @@ index c7ab95482..3e93da36e 100644
9898
- def removesuffix(self: LiteralString, suffix: LiteralString, /) -> LiteralString: ...
9999
- @overload
100100
def removesuffix(self, suffix: str, /) -> str: ... # type: ignore[misc]
101-
def rfind(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
102-
def rindex(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
101+
def rfind(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
102+
def rindex(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
103103
- @overload
104104
- def rjust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
105105
- @overload
@@ -125,7 +125,7 @@ index c7ab95482..3e93da36e 100644
125125
- @overload
126126
def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc]
127127
def startswith(
128-
self, prefix: str | tuple[str, ...], start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
128+
self, prefix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
129129
) -> bool: ...
130130
- @overload
131131
- def strip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
@@ -150,7 +150,7 @@ index c7ab95482..3e93da36e 100644
150150
def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc]
151151
@staticmethod
152152
@overload
153-
@@ -610,39 +530,21 @@ class str(Sequence[str]):
153+
@@ -622,39 +542,21 @@ class str(Sequence[str]):
154154
@staticmethod
155155
@overload
156156
def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ...
@@ -192,5 +192,5 @@ index c7ab95482..3e93da36e 100644
192192
def __getnewargs__(self) -> tuple[str]: ...
193193
def __format__(self, format_spec: str, /) -> str: ...
194194
--
195-
2.50.1
195+
2.51.1
196196

misc/typeshed_patches/0001-Revert-Remove-redundant-inheritances-from-Iterator.patch

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 438dbb1300b77331940d7db8f010e97305745116 Mon Sep 17 00:00:00 2001
1+
From 7678bc3f80e4d3f04a0ff0ee3a7d51f49ae4c465 Mon Sep 17 00:00:00 2001
22
From: Marc Mueller <[email protected]>
33
Date: Sat, 21 Dec 2024 22:36:38 +0100
44
Subject: [PATCH] Revert Remove redundant inheritances from Iterator in
@@ -36,10 +36,10 @@ index d663f5d93..f43178e4d 100644
3636
@property
3737
def _exception(self) -> BaseException | None: ...
3838
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
39-
index f2dd00079..784ee7eac 100644
39+
index 044e264d2..6d813f172 100644
4040
--- a/mypy/typeshed/stdlib/builtins.pyi
4141
+++ b/mypy/typeshed/stdlib/builtins.pyi
42-
@@ -1209,7 +1209,7 @@ class frozenset(AbstractSet[_T_co]):
42+
@@ -1210,7 +1210,7 @@ class frozenset(AbstractSet[_T_co]):
4343
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
4444

4545
@disjoint_base
@@ -48,7 +48,7 @@ index f2dd00079..784ee7eac 100644
4848
def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ...
4949
def __iter__(self) -> Self: ...
5050
def __next__(self) -> tuple[int, _T]: ...
51-
@@ -1405,7 +1405,7 @@ else:
51+
@@ -1404,7 +1404,7 @@ else:
5252
exit: _sitebuiltins.Quitter
5353

5454
@disjoint_base
@@ -57,7 +57,7 @@ index f2dd00079..784ee7eac 100644
5757
@overload
5858
def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ...
5959
@overload
60-
@@ -1469,7 +1469,7 @@ license: _sitebuiltins._Printer
60+
@@ -1468,7 +1468,7 @@ license: _sitebuiltins._Printer
6161

6262
def locals() -> dict[str, Any]: ...
6363
@disjoint_base
@@ -66,7 +66,7 @@ index f2dd00079..784ee7eac 100644
6666
# 3.14 adds `strict` argument.
6767
if sys.version_info >= (3, 14):
6868
@overload
69-
@@ -1776,7 +1776,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
69+
@@ -1775,7 +1775,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
7070
quit: _sitebuiltins.Quitter
7171

7272
@disjoint_base
@@ -75,15 +75,15 @@ index f2dd00079..784ee7eac 100644
7575
@overload
7676
def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc]
7777
@overload
78-
@@ -1840,7 +1840,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
78+
@@ -1839,7 +1839,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
7979
@overload
8080
def vars(object: Any = ..., /) -> dict[str, Any]: ...
8181
@disjoint_base
8282
-class zip(Generic[_T_co]):
8383
+class zip(Iterator[_T_co]):
8484
if sys.version_info >= (3, 10):
8585
@overload
86-
def __new__(cls, *, strict: bool = ...) -> zip[Any]: ...
86+
def __new__(cls, *, strict: bool = False) -> zip[Any]: ...
8787
diff --git a/mypy/typeshed/stdlib/csv.pyi b/mypy/typeshed/stdlib/csv.pyi
8888
index 2c8e7109c..4ed0ab1d8 100644
8989
--- a/mypy/typeshed/stdlib/csv.pyi
@@ -326,5 +326,5 @@ index 6b0f1ba94..882cd143c 100644
326326
@property
327327
def connection(self) -> Connection: ...
328328
--
329-
2.51.0
329+
2.51.1
330330

mypy-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ typing_extensions>=4.6.0
44
mypy_extensions>=1.0.0
55
pathspec>=0.9.0
66
tomli>=1.1.0; python_version<'3.11'
7-
librt>=0.1.0
7+
librt>=0.2.1

0 commit comments

Comments
 (0)