You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This way existing use cases that parse JSON cache files can be supported when using
47
+
the new format, though an extra conversion step is needed.
48
+
49
+
This release includes these improvements:
50
+
51
+
- Force-discard cache if cache format changed (Ivan Levkivskyi, PR [20152](https://github.com/python/mypy/pull/20152))
52
+
- Add tool to convert binary cache files to JSON (Jukka Lehtosalo, PR [20071](https://github.com/python/mypy/pull/20071))
53
+
- Use more efficient serialization format for long integers in cache files (Jukka Lehtosalo, PR [20151](https://github.com/python/mypy/pull/20151))
54
+
- More robust packing of floats in fixed-format cache (Ivan Levkivskyi, PR [20150](https://github.com/python/mypy/pull/20150))
55
+
- Use self-descriptive cache with type tags (Ivan Levkivskyi, PR [20137](https://github.com/python/mypy/pull/20137))
56
+
- Use fixed format for cache metas (Ivan Levkivskyi, PR [20088](https://github.com/python/mypy/pull/20088))
57
+
- Make metas more compact; fix indirect suppression (Ivan Levkivskyi, PR [20075](https://github.com/python/mypy/pull/20075))
58
+
- Use dedicated tags for most common cached instances (Ivan Levkivskyi, PR [19762](https://github.com/python/mypy/pull/19762))
59
+
60
+
### PEP 747: Annotating Type Forms
61
+
62
+
Mypy now recognizes `TypeForm[T]` as a type and implements
63
+
[PEP 747](https://peps.python.org/pep-0747/). The feature is still experimental,
64
+
and it's disabled by default. Use `--enable-incomplete-feature=TypeForm` to
65
+
enable type forms. A type form object captures the type information provided by a
66
+
runtime type expression. Example:
67
+
68
+
```python
69
+
from typing_extensions import TypeForm
70
+
71
+
def trycast[T](typx: TypeForm[T], value: object) -> T |None: ...
72
+
73
+
defexample(o: object) -> None:
74
+
# 'int | str' below is an expression that represents a type.
75
+
# Unlike type[T], TypeForm[T] can be used with all kinds of types,
76
+
# including union types.
77
+
x = trycast(int|str, o)
78
+
if x isnotNone:
79
+
# Type of 'x' is 'int | str' here
80
+
...
81
+
```
82
+
83
+
This feature was contributed by David Foster (PR [19596](https://github.com/python/mypy/pull/19596)).
84
+
85
+
### Fixes to Crashes
86
+
- Do not push partial types to the binder (Stanislav Terliakov, PR [20202](https://github.com/python/mypy/pull/20202))
87
+
- Fix crash on recursive tuple with Hashable (Ivan Levkivskyi, PR [20232](https://github.com/python/mypy/pull/20232))
88
+
- Fix crash related to decorated functions (Stanislav Terliakov, PR [20203](https://github.com/python/mypy/pull/20203))
89
+
- Do not abort constructing TypeAlias if only type parameters hold us back (Stanislav Terliakov, PR [20162](https://github.com/python/mypy/pull/20162))
90
+
- Use the fallback for `ModuleSpec` early if it can never be resolved (Stanislav Terliakov, PR [20167](https://github.com/python/mypy/pull/20167))
91
+
- Do not store deferred NamedTuple fields as redefinitions (Stanislav Terliakov, PR [20147](https://github.com/python/mypy/pull/20147))
- Fix an infinite recursion bug (Stanislav Terliakov, PR [20127](https://github.com/python/mypy/pull/20127))
94
+
- Fix IsADirectoryError for namespace packages when using --linecoverage-report (wyattscarpenter, PR [20109](https://github.com/python/mypy/pull/20109))
95
+
- Fix an internal error when creating cobertura output for namespace package (wyattscarpenter, PR [20112](https://github.com/python/mypy/pull/20112))
96
+
- Allow type parameters reusing the name missing from current module (Stanislav Terliakov, PR [20081](https://github.com/python/mypy/pull/20081))
97
+
- Prevent TypeGuardedType leak from narrowing declared type as part of type variable bound (Stanislav Terliakov, PR [20046](https://github.com/python/mypy/pull/20046))
98
+
- Fix crash on invalid unpack in base class (Ivan Levkivskyi, PR [19962](https://github.com/python/mypy/pull/19962))
99
+
- Traverse ParamSpec prefix where we should (Ivan Levkivskyi, PR [19800](https://github.com/python/mypy/pull/19800))
100
+
- Fix daemon crash related to imports (Ivan Levkivskyi, PR [20271](https://github.com/python/mypy/pull/20271))
101
+
102
+
### Mypyc: Support for `__getattr__`, `__setattr__`, and `__delattr__`
103
+
104
+
Mypyc now has partial support for `__getattr__`, `__setattr__` and
105
+
`__delattr__` methods in native classes.
106
+
107
+
Note that native attributes are not stored using `__dict__`. Setting attributes
108
+
directly while bypassing `__setattr__` is possible by using
109
+
`super().__setattr__(...)` or `object.__setattr__(...)`, but not via `__dict__`.
110
+
111
+
Example:
112
+
```python
113
+
classDemo:
114
+
_data: dict[str, str]
115
+
116
+
def__init__(self) -> None:
117
+
# Initialize data dict without calling our __setattr__
- Fix crash with NewType and other non-class types in incremental builds (Jukka Lehtosalo, PR [19837](https://github.com/python/mypy/pull/19837))
162
+
- Optimize container creation from expressions with length known at compile time (BobTheBuidler, PR [19503](https://github.com/python/mypy/pull/19503))
163
+
- Allow per-class free list to be used with inheritance (Jukka Lehtosalo, PR [19790](https://github.com/python/mypy/pull/19790))
- Fix annotated with function as type keyword list parameter (KarelKenens, PR [20094](https://github.com/python/mypy/pull/20094))
183
+
- Fix errors for raise NotImplemented (Shantanu, PR [20168](https://github.com/python/mypy/pull/20168))
184
+
- Don't let help formatter line-wrap URLs (Frank Dana, PR [19825](https://github.com/python/mypy/pull/19825))
185
+
- Do not cache fast container types inside lambdas (Stanislav Terliakov, PR [20166](https://github.com/python/mypy/pull/20166))
186
+
- Respect force-union-syntax flag in error hint (Marc Mueller, PR [20165](https://github.com/python/mypy/pull/20165))
187
+
- Fix type checking of dict type aliases (Shantanu, PR [20170](https://github.com/python/mypy/pull/20170))
188
+
- Use pretty callable formatting more often for callable expressions (Theodore Ando, PR [20128](https://github.com/python/mypy/pull/20128))
189
+
- Use dummy concrete type instead of `Any` when checking protocol variance (bzoracler, PR [20110](https://github.com/python/mypy/pull/20110))
190
+
- PEP 696: Fix swapping TypeVars with defaults (Randolf Scholz, PR [19449](https://github.com/python/mypy/pull/19449))
191
+
- Fix narrowing of class pattern with union type (Randolf Scholz, PR [19517](https://github.com/python/mypy/pull/19517))
192
+
- Do not emit unreachable warnings for lines that return `NotImplemented` (Christoph Tyralla, PR [20083](https://github.com/python/mypy/pull/20083))
193
+
- Fix matching against `typing.Callable` and `Protocol` types (Randolf Scholz, PR [19471](https://github.com/python/mypy/pull/19471))
194
+
- Make `--pretty` work better on multi-line issues (A5rocks, PR [20056](https://github.com/python/mypy/pull/20056))
195
+
- More precise return types for `TypedDict.get` (Randolf Scholz, PR [19897](https://github.com/python/mypy/pull/19897))
196
+
- Prevent false unreachable warnings for `@final` instances that occur when strict optional checking is disabled (Christoph Tyralla, PR [20045](https://github.com/python/mypy/pull/20045))
197
+
- Check class references to catch non-existent classes in match cases (A5rocks, PR [20042](https://github.com/python/mypy/pull/20042))
198
+
- Do not sort unused error codes in unused error codes warning (wyattscarpenter, PR [20036](https://github.com/python/mypy/pull/20036))
199
+
- Fix `[name-defined]` false positive in `class A[X, Y=X]:` case (sobolevn, PR [20021](https://github.com/python/mypy/pull/20021))
200
+
- Filter SyntaxWarnings during AST parsing (Marc Mueller, PR [20023](https://github.com/python/mypy/pull/20023))
201
+
- Make untyped decorator its own error code (wyattscarpenter, PR [19911](https://github.com/python/mypy/pull/19911))
202
+
- Support error codes from plugins in options (Sigve Sebastian Farstad, PR [19719](https://github.com/python/mypy/pull/19719))
203
+
- Allow returning Literals in `__new__` (James Hilton-Balfe, PR [15687](https://github.com/python/mypy/pull/15687))
Please see [git log](https://github.com/python/typeshed/commits/main?after=ebce8d766b41fbf4d83cf47c1297563a9508ff60+0&branch=main&path=stdlib) for full list of standard library typeshed stub changes.
213
+
214
+
### Acknowledgements
215
+
216
+
Thanks to all mypy contributors who contributed to this release:
217
+
- A5rocks
218
+
- BobTheBuidler
219
+
- bzoracler
220
+
- Chainfire
221
+
- Christoph Tyralla
222
+
- David Foster
223
+
- Frank Dana
224
+
- Guo Ci
225
+
- iap
226
+
- Ivan Levkivskyi
227
+
- James Hilton-Balfe
228
+
- jhance
229
+
- Joren Hammudoglu
230
+
- Jukka Lehtosalo
231
+
- KarelKenens
232
+
- Kevin Kannammalil
233
+
- Marc Mueller
234
+
- Michael Carlstrom
235
+
- Michael J. Sullivan
236
+
- Piotr Sawicki
237
+
- Randolf Scholz
238
+
- Shantanu
239
+
- Sigve Sebastian Farstad
240
+
- sobolevn
241
+
- Stanislav Terliakov
242
+
- Stephen Morton
243
+
- Theodore Ando
244
+
- Thiago J. Barbalho
245
+
- wyattscarpenter
246
+
247
+
I’d also like to thank my employer, Dropbox, for supporting mypy development.
248
+
14
249
## Mypy 1.18.1
15
250
16
251
We’ve just uploaded mypy 1.18.1 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
0 commit comments