Skip to content

Commit 0050b5c

Browse files
Merge branch 'master' into truedictprimitive
2 parents a076268 + 9edd29a commit 0050b5c

File tree

298 files changed

+7153
-3457
lines changed

Some content is hidden

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

298 files changed

+7153
-3457
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ Mypy can be integrated into popular IDEs:
142142
- Emacs: using [Flycheck](https://github.com/flycheck/)
143143
- Sublime Text: [SublimeLinter-contrib-mypy](https://github.com/fredcallaway/SublimeLinter-contrib-mypy)
144144
- PyCharm: [mypy plugin](https://github.com/dropbox/mypy-PyCharm-plugin)
145+
- IDLE: [idlemypyextension](https://github.com/CoolCat467/idlemypyextension)
145146
- pre-commit: use [pre-commit mirrors-mypy](https://github.com/pre-commit/mirrors-mypy), although
146147
note by default this will limit mypy's ability to analyse your third party dependencies.
147148

docs/requirements-docs.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
-r ../mypy-requirements.txt
12
sphinx>=8.1.0
23
furo>=2022.3.4
34
myst-parser>=4.0.0

docs/source/command_line.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,9 +728,22 @@ of the above sections.
728728
if text != b'other bytes': # Error: non-overlapping equality check!
729729
...
730730
731-
assert text is not None # OK, check against None is allowed as a special case.
731+
assert text is not None # OK, check against None is allowed
732732
733733
734+
.. option:: --strict-equality-for-none
735+
736+
This flag extends :option:`--strict-equality <mypy --strict-equality>` for checks
737+
against ``None``:
738+
739+
.. code-block:: python
740+
741+
text: str
742+
assert text is not None # Error: non-overlapping identity check!
743+
744+
Note that :option:`--strict-equality-for-none <mypy --strict-equality-for-none>`
745+
only works in combination with :option:`--strict-equality <mypy --strict-equality>`.
746+
734747
.. option:: --strict-bytes
735748

736749
By default, mypy treats ``bytearray`` and ``memoryview`` as subtypes of ``bytes`` which

docs/source/config_file.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,15 @@ section of the command line docs.
834834
:default: False
835835

836836
Prohibit equality checks, identity checks, and container checks between
837-
non-overlapping types.
837+
non-overlapping types (except ``None``).
838+
839+
.. confval:: strict_equality_for_none
840+
841+
:type: boolean
842+
:default: False
843+
844+
Include ``None`` in strict equality checks (requires :confval:`strict_equality`
845+
to be activated).
838846

839847
.. confval:: strict_bytes
840848

docs/source/error_code_list2.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,29 @@ literal:
145145
def is_magic(x: bytes) -> bool:
146146
return x == b'magic' # OK
147147
148+
:option:`--strict-equality <mypy --strict-equality>` does not include comparisons with
149+
``None``:
150+
151+
.. code-block:: python
152+
153+
# mypy: strict-equality
154+
155+
def is_none(x: str) -> bool:
156+
return x is None # OK
157+
158+
If you want such checks, you must also activate
159+
:option:`--strict-equality-for-none <mypy --strict-equality-for-none>` (we might merge
160+
these two options later).
161+
162+
.. code-block:: python
163+
164+
# mypy: strict-equality strict-equality-for-none
165+
166+
def is_none(x: str) -> bool:
167+
# Error: Non-overlapping identity check
168+
# (left operand type: "str", right operand type: "None")
169+
return x is None
170+
148171
.. _code-no-untyped-call:
149172

150173
Check that no untyped functions are called [no-untyped-call]

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

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From c217544146d36899d50e828d627652a0d8f63bb7 Mon Sep 17 00:00:00 2001
1+
From 438dbb1300b77331940d7db8f010e97305745116 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
@@ -15,7 +15,7 @@ Subject: [PATCH] Revert Remove redundant inheritances from Iterator in
1515
7 files changed, 34 insertions(+), 34 deletions(-)
1616

1717
diff --git a/mypy/typeshed/stdlib/_asyncio.pyi b/mypy/typeshed/stdlib/_asyncio.pyi
18-
index ed56f33af..5253e967e 100644
18+
index d663f5d93..f43178e4d 100644
1919
--- a/mypy/typeshed/stdlib/_asyncio.pyi
2020
+++ b/mypy/typeshed/stdlib/_asyncio.pyi
2121
@@ -1,6 +1,6 @@
@@ -26,59 +26,59 @@ index ed56f33af..5253e967e 100644
2626
from contextvars import Context
2727
from types import FrameType, GenericAlias
2828
from typing import Any, Literal, TextIO, TypeVar
29-
@@ -10,7 +10,7 @@ _T = TypeVar("_T")
30-
_T_co = TypeVar("_T_co", covariant=True)
29+
@@ -11,7 +11,7 @@ _T_co = TypeVar("_T_co", covariant=True)
3130
_TaskYieldType: TypeAlias = Future[object] | None
3231

32+
@disjoint_base
3333
-class Future(Awaitable[_T]):
3434
+class Future(Awaitable[_T], Iterable[_T]):
3535
_state: str
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 0575be3c8..d9be595fe 100644
39+
index f2dd00079..784ee7eac 100644
4040
--- a/mypy/typeshed/stdlib/builtins.pyi
4141
+++ b/mypy/typeshed/stdlib/builtins.pyi
42-
@@ -1186,7 +1186,7 @@ class frozenset(AbstractSet[_T_co]):
43-
def __hash__(self) -> int: ...
42+
@@ -1209,7 +1209,7 @@ class frozenset(AbstractSet[_T_co]):
4443
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
4544

45+
@disjoint_base
4646
-class enumerate(Generic[_T]):
4747
+class enumerate(Iterator[tuple[int, _T]]):
4848
def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ...
4949
def __iter__(self) -> Self: ...
5050
def __next__(self) -> tuple[int, _T]: ...
51-
@@ -1380,7 +1380,7 @@ else:
52-
51+
@@ -1405,7 +1405,7 @@ else:
5352
exit: _sitebuiltins.Quitter
5453

54+
@disjoint_base
5555
-class filter(Generic[_T]):
5656
+class filter(Iterator[_T]):
5757
@overload
5858
def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ...
5959
@overload
60-
@@ -1444,7 +1444,7 @@ license: _sitebuiltins._Printer
60+
@@ -1469,7 +1469,7 @@ license: _sitebuiltins._Printer
6161

6262
def locals() -> dict[str, Any]: ...
63-
63+
@disjoint_base
6464
-class map(Generic[_S]):
6565
+class map(Iterator[_S]):
6666
# 3.14 adds `strict` argument.
6767
if sys.version_info >= (3, 14):
6868
@overload
69-
@@ -1750,7 +1750,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
70-
69+
@@ -1776,7 +1776,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
7170
quit: _sitebuiltins.Quitter
7271

72+
@disjoint_base
7373
-class reversed(Generic[_T]):
7474
+class reversed(Iterator[_T]):
7575
@overload
7676
def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc]
7777
@overload
78-
@@ -1814,7 +1814,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
78+
@@ -1840,7 +1840,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
7979
@overload
8080
def vars(object: Any = ..., /) -> dict[str, Any]: ...
81-
81+
@disjoint_base
8282
-class zip(Generic[_T_co]):
8383
+class zip(Iterator[_T_co]):
8484
if sys.version_info >= (3, 10):
@@ -131,157 +131,163 @@ index 910d63814..eb942bc55 100644
131131
# encoding and errors are added
132132
@overload
133133
diff --git a/mypy/typeshed/stdlib/itertools.pyi b/mypy/typeshed/stdlib/itertools.pyi
134-
index d0085dd72..7d05b1318 100644
134+
index fe4ccbdf8..73745fe92 100644
135135
--- a/mypy/typeshed/stdlib/itertools.pyi
136136
+++ b/mypy/typeshed/stdlib/itertools.pyi
137-
@@ -27,7 +27,7 @@ _Predicate: TypeAlias = Callable[[_T], object]
138-
137+
@@ -28,7 +28,7 @@ _Predicate: TypeAlias = Callable[[_T], object]
139138
# Technically count can take anything that implements a number protocol and has an add method
140139
# but we can't enforce the add method
140+
@disjoint_base
141141
-class count(Generic[_N]):
142142
+class count(Iterator[_N]):
143143
@overload
144144
def __new__(cls) -> count[int]: ...
145145
@overload
146-
@@ -37,12 +37,12 @@ class count(Generic[_N]):
147-
def __next__(self) -> _N: ...
146+
@@ -39,13 +39,13 @@ class count(Generic[_N]):
148147
def __iter__(self) -> Self: ...
149148

149+
@disjoint_base
150150
-class cycle(Generic[_T]):
151151
+class cycle(Iterator[_T]):
152152
def __new__(cls, iterable: Iterable[_T], /) -> Self: ...
153153
def __next__(self) -> _T: ...
154154
def __iter__(self) -> Self: ...
155155

156+
@disjoint_base
156157
-class repeat(Generic[_T]):
157158
+class repeat(Iterator[_T]):
158159
@overload
159160
def __new__(cls, object: _T) -> Self: ...
160161
@overload
161-
@@ -51,7 +51,7 @@ class repeat(Generic[_T]):
162-
def __iter__(self) -> Self: ...
162+
@@ -55,7 +55,7 @@ class repeat(Generic[_T]):
163163
def __length_hint__(self) -> int: ...
164164

165+
@disjoint_base
165166
-class accumulate(Generic[_T]):
166167
+class accumulate(Iterator[_T]):
167168
@overload
168169
def __new__(cls, iterable: Iterable[_T], func: None = None, *, initial: _T | None = ...) -> Self: ...
169170
@overload
170-
@@ -59,7 +59,7 @@ class accumulate(Generic[_T]):
171-
def __iter__(self) -> Self: ...
171+
@@ -64,7 +64,7 @@ class accumulate(Generic[_T]):
172172
def __next__(self) -> _T: ...
173173

174+
@disjoint_base
174175
-class chain(Generic[_T]):
175176
+class chain(Iterator[_T]):
176177
def __new__(cls, *iterables: Iterable[_T]) -> Self: ...
177178
def __next__(self) -> _T: ...
178179
def __iter__(self) -> Self: ...
179-
@@ -68,22 +68,22 @@ class chain(Generic[_T]):
180-
def from_iterable(cls: type[Any], iterable: Iterable[Iterable[_S]], /) -> chain[_S]: ...
180+
@@ -74,25 +74,25 @@ class chain(Generic[_T]):
181181
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
182182

183+
@disjoint_base
183184
-class compress(Generic[_T]):
184185
+class compress(Iterator[_T]):
185186
def __new__(cls, data: Iterable[_T], selectors: Iterable[Any]) -> Self: ...
186187
def __iter__(self) -> Self: ...
187188
def __next__(self) -> _T: ...
188189

190+
@disjoint_base
189191
-class dropwhile(Generic[_T]):
190192
+class dropwhile(Iterator[_T]):
191193
def __new__(cls, predicate: _Predicate[_T], iterable: Iterable[_T], /) -> Self: ...
192194
def __iter__(self) -> Self: ...
193195
def __next__(self) -> _T: ...
194196

197+
@disjoint_base
195198
-class filterfalse(Generic[_T]):
196199
+class filterfalse(Iterator[_T]):
197200
def __new__(cls, function: _Predicate[_T] | None, iterable: Iterable[_T], /) -> Self: ...
198201
def __iter__(self) -> Self: ...
199202
def __next__(self) -> _T: ...
200203

204+
@disjoint_base
201205
-class groupby(Generic[_T_co, _S_co]):
202206
+class groupby(Iterator[tuple[_T_co, Iterator[_S_co]]], Generic[_T_co, _S_co]):
203207
@overload
204208
def __new__(cls, iterable: Iterable[_T1], key: None = None) -> groupby[_T1, _T1]: ...
205209
@overload
206-
@@ -91,7 +91,7 @@ class groupby(Generic[_T_co, _S_co]):
207-
def __iter__(self) -> Self: ...
210+
@@ -101,7 +101,7 @@ class groupby(Generic[_T_co, _S_co]):
208211
def __next__(self) -> tuple[_T_co, Iterator[_S_co]]: ...
209212

213+
@disjoint_base
210214
-class islice(Generic[_T]):
211215
+class islice(Iterator[_T]):
212216
@overload
213217
def __new__(cls, iterable: Iterable[_T], stop: int | None, /) -> Self: ...
214218
@overload
215-
@@ -99,19 +99,19 @@ class islice(Generic[_T]):
216-
def __iter__(self) -> Self: ...
219+
@@ -110,20 +110,20 @@ class islice(Generic[_T]):
217220
def __next__(self) -> _T: ...
218221

222+
@disjoint_base
219223
-class starmap(Generic[_T_co]):
220224
+class starmap(Iterator[_T_co]):
221225
def __new__(cls, function: Callable[..., _T], iterable: Iterable[Iterable[Any]], /) -> starmap[_T]: ...
222226
def __iter__(self) -> Self: ...
223227
def __next__(self) -> _T_co: ...
224228

229+
@disjoint_base
225230
-class takewhile(Generic[_T]):
226231
+class takewhile(Iterator[_T]):
227232
def __new__(cls, predicate: _Predicate[_T], iterable: Iterable[_T], /) -> Self: ...
228233
def __iter__(self) -> Self: ...
229234
def __next__(self) -> _T: ...
230235

231236
def tee(iterable: Iterable[_T], n: int = 2, /) -> tuple[Iterator[_T], ...]: ...
232-
237+
@disjoint_base
233238
-class zip_longest(Generic[_T_co]):
234239
+class zip_longest(Iterator[_T_co]):
235240
# one iterable (fillvalue doesn't matter)
236241
@overload
237242
def __new__(cls, iter1: Iterable[_T1], /, *, fillvalue: object = ...) -> zip_longest[tuple[_T1]]: ...
238-
@@ -189,7 +189,7 @@ class zip_longest(Generic[_T_co]):
239-
def __iter__(self) -> Self: ...
243+
@@ -202,7 +202,7 @@ class zip_longest(Generic[_T_co]):
240244
def __next__(self) -> _T_co: ...
241245

246+
@disjoint_base
242247
-class product(Generic[_T_co]):
243248
+class product(Iterator[_T_co]):
244249
@overload
245250
def __new__(cls, iter1: Iterable[_T1], /) -> product[tuple[_T1]]: ...
246251
@overload
247-
@@ -274,7 +274,7 @@ class product(Generic[_T_co]):
248-
def __iter__(self) -> Self: ...
252+
@@ -288,7 +288,7 @@ class product(Generic[_T_co]):
249253
def __next__(self) -> _T_co: ...
250254

255+
@disjoint_base
251256
-class permutations(Generic[_T_co]):
252257
+class permutations(Iterator[_T_co]):
253258
@overload
254259
def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> permutations[tuple[_T, _T]]: ...
255260
@overload
256-
@@ -288,7 +288,7 @@ class permutations(Generic[_T_co]):
257-
def __iter__(self) -> Self: ...
261+
@@ -303,7 +303,7 @@ class permutations(Generic[_T_co]):
258262
def __next__(self) -> _T_co: ...
259263

264+
@disjoint_base
260265
-class combinations(Generic[_T_co]):
261266
+class combinations(Iterator[_T_co]):
262267
@overload
263268
def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> combinations[tuple[_T, _T]]: ...
264269
@overload
265-
@@ -302,7 +302,7 @@ class combinations(Generic[_T_co]):
266-
def __iter__(self) -> Self: ...
270+
@@ -318,7 +318,7 @@ class combinations(Generic[_T_co]):
267271
def __next__(self) -> _T_co: ...
268272

273+
@disjoint_base
269274
-class combinations_with_replacement(Generic[_T_co]):
270275
+class combinations_with_replacement(Iterator[_T_co]):
271276
@overload
272277
def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> combinations_with_replacement[tuple[_T, _T]]: ...
273278
@overload
274-
@@ -317,13 +317,13 @@ class combinations_with_replacement(Generic[_T_co]):
275-
def __next__(self) -> _T_co: ...
279+
@@ -334,14 +334,14 @@ class combinations_with_replacement(Generic[_T_co]):
276280

277281
if sys.version_info >= (3, 10):
282+
@disjoint_base
278283
- class pairwise(Generic[_T_co]):
279284
+ class pairwise(Iterator[_T_co]):
280285
def __new__(cls, iterable: Iterable[_T], /) -> pairwise[tuple[_T, _T]]: ...
281286
def __iter__(self) -> Self: ...
282287
def __next__(self) -> _T_co: ...
283288

284289
if sys.version_info >= (3, 12):
290+
@disjoint_base
285291
- class batched(Generic[_T_co]):
286292
+ class batched(Iterator[tuple[_T_co, ...]], Generic[_T_co]):
287293
if sys.version_info >= (3, 13):
@@ -307,18 +313,18 @@ index b79f9e773..f276372d0 100644
307313
def __iter__(self) -> Self: ...
308314
def next(self, timeout: float | None = None) -> _T: ...
309315
diff --git a/mypy/typeshed/stdlib/sqlite3/__init__.pyi b/mypy/typeshed/stdlib/sqlite3/__init__.pyi
310-
index bcfea3a13..5a659deac 100644
316+
index 6b0f1ba94..882cd143c 100644
311317
--- a/mypy/typeshed/stdlib/sqlite3/__init__.pyi
312318
+++ b/mypy/typeshed/stdlib/sqlite3/__init__.pyi
313-
@@ -405,7 +405,7 @@ class Connection:
314-
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None, /
319+
@@ -407,7 +407,7 @@ class Connection:
315320
) -> Literal[False]: ...
316321

322+
@disjoint_base
317323
-class Cursor:
318324
+class Cursor(Iterator[Any]):
319325
arraysize: int
320326
@property
321327
def connection(self) -> Connection: ...
322328
--
323-
2.50.1
329+
2.51.0
324330

misc/update-stubinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def main() -> None:
5858
print("Consider removing the following packages no longer in typeshed:")
5959
print("=" * 40)
6060
for p in sorted(mypy_p - typeshed_p_to_d.keys()):
61-
if p in {"lxml", "pandas"}: # never in typeshed
61+
if p in {"lxml", "pandas", "scipy"}: # never in typeshed
6262
continue
6363
print(p)
6464

0 commit comments

Comments
 (0)