|
2 | 2 |
|
3 | 3 | ## Next Release |
4 | 4 |
|
| 5 | +### Drop Support for Python 3.9 |
| 6 | + |
| 7 | +Mypy no longer supports running with Python 3.9, which has reached end-of-life. |
| 8 | +When running mypy with Python 3.10+, it is still possible to type check code |
| 9 | +that needs to support Python 3.9 with the `--python-version 3.9` argument. |
| 10 | +Support for this will be dropped in the first half of 2026! |
| 11 | + |
| 12 | +Contributed by Marc Mueller (PR [20156](https://github.com/python/mypy/pull/20156)). |
| 13 | + |
| 14 | +## Mypy 1.19 |
| 15 | + |
| 16 | +We’ve just uploaded mypy 1.19.0 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)). |
| 17 | +Mypy is a static type checker for Python. This release includes new features, performance |
| 18 | +improvements and bug fixes. You can install it as follows: |
| 19 | + |
| 20 | + python3 -m pip install -U mypy |
| 21 | + |
| 22 | +You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io). |
| 23 | + |
| 24 | +### Python 3.9 Support Ending Soon |
| 25 | + |
| 26 | +This is the last mypy feature release that supports Python 3.9, which reached |
| 27 | +end of life in October 2025. |
| 28 | + |
| 29 | +### Performance Improvements |
| 30 | +- Switch to a more dynamic SCC processing logic (Ivan Levkivskyi, PR [20053](https://github.com/python/mypy/pull/20053)) |
| 31 | +- Speed up type aliases (Ivan Levkivskyi, PR [19810](https://github.com/python/mypy/pull/19810)) |
| 32 | + |
| 33 | +### Fixed‑Format Cache Improvements |
| 34 | + |
| 35 | +Mypy uses a cache by default to speed up incremental runs by reusing partial results |
| 36 | +from earlier runs. Mypy 1.18 added a new binary fixed-format cache representation as |
| 37 | +an experimental feature. The feature is no longer experimental, and we are planning |
| 38 | +to enable it by default in a future mypy release (possibly 1.20), since it's faster |
| 39 | +and uses less space than the original, JSON-based cache format. Use |
| 40 | +`--fixed-format-cache` to enable the fixed-format cache. |
| 41 | + |
| 42 | +Mypy now has an extra dependency on the `librt` PyPI package, as it's needed for |
| 43 | +cache serialization and deserialization. |
| 44 | + |
| 45 | +Mypy ships with a tool to convert fixed-format cache files to the old JSON format. |
| 46 | +Example of how to use this: |
| 47 | +``` |
| 48 | +$ python -m mypy.exportjson .mypy_cache/.../my_module.data.ff |
| 49 | +``` |
| 50 | + |
| 51 | +This way existing use cases that parse JSON cache files can be supported when using |
| 52 | +the new format, though an extra conversion step is needed. |
| 53 | + |
| 54 | +This release includes these improvements: |
| 55 | + |
| 56 | +- Force-discard cache if cache format changed (Ivan Levkivskyi, PR [20152](https://github.com/python/mypy/pull/20152)) |
| 57 | +- Add tool to convert binary cache files to JSON (Jukka Lehtosalo, PR [20071](https://github.com/python/mypy/pull/20071)) |
| 58 | +- Use more efficient serialization format for long integers in cache files (Jukka Lehtosalo, PR [20151](https://github.com/python/mypy/pull/20151)) |
| 59 | +- More robust packing of floats in fixed-format cache (Ivan Levkivskyi, PR [20150](https://github.com/python/mypy/pull/20150)) |
| 60 | +- Use self-descriptive cache with type tags (Ivan Levkivskyi, PR [20137](https://github.com/python/mypy/pull/20137)) |
| 61 | +- Use fixed format for cache metas (Ivan Levkivskyi, PR [20088](https://github.com/python/mypy/pull/20088)) |
| 62 | +- Make metas more compact; fix indirect suppression (Ivan Levkivskyi, PR [20075](https://github.com/python/mypy/pull/20075)) |
| 63 | +- Use dedicated tags for most common cached instances (Ivan Levkivskyi, PR [19762](https://github.com/python/mypy/pull/19762)) |
| 64 | + |
| 65 | +### PEP 747: Annotating Type Forms |
| 66 | + |
| 67 | +Mypy now recognizes `TypeForm[T]` as a type and implements |
| 68 | +[PEP 747](https://peps.python.org/pep-0747/). The feature is still experimental, |
| 69 | +and it's disabled by default. Use `--enable-incomplete-feature=TypeForm` to |
| 70 | +enable type forms. A type form object captures the type information provided by a |
| 71 | +runtime type expression. Example: |
| 72 | + |
| 73 | +```python |
| 74 | +from typing_extensions import TypeForm |
| 75 | + |
| 76 | +def trycast[T](typx: TypeForm[T], value: object) -> T | None: ... |
| 77 | + |
| 78 | +def example(o: object) -> None: |
| 79 | + # 'int | str' below is an expression that represents a type. |
| 80 | + # Unlike type[T], TypeForm[T] can be used with all kinds of types, |
| 81 | + # including union types. |
| 82 | + x = trycast(int | str, o) |
| 83 | + if x is not None: |
| 84 | + # Type of 'x' is 'int | str' here |
| 85 | + ... |
| 86 | +``` |
| 87 | + |
| 88 | +This feature was contributed by David Foster (PR [19596](https://github.com/python/mypy/pull/19596)). |
| 89 | + |
| 90 | +### Fixes to Crashes |
| 91 | +- Do not push partial types to the binder (Stanislav Terliakov, PR [20202](https://github.com/python/mypy/pull/20202)) |
| 92 | +- Fix crash on recursive tuple with Hashable (Ivan Levkivskyi, PR [20232](https://github.com/python/mypy/pull/20232)) |
| 93 | +- Fix crash related to decorated functions (Stanislav Terliakov, PR [20203](https://github.com/python/mypy/pull/20203)) |
| 94 | +- Do not abort constructing TypeAlias if only type parameters hold us back (Stanislav Terliakov, PR [20162](https://github.com/python/mypy/pull/20162)) |
| 95 | +- Use the fallback for `ModuleSpec` early if it can never be resolved (Stanislav Terliakov, PR [20167](https://github.com/python/mypy/pull/20167)) |
| 96 | +- Do not store deferred NamedTuple fields as redefinitions (Stanislav Terliakov, PR [20147](https://github.com/python/mypy/pull/20147)) |
| 97 | +- Discard partial types remaining after inference failure (Stanislav Terliakov, PR [20126](https://github.com/python/mypy/pull/20126)) |
| 98 | +- Fix an infinite recursion bug (Stanislav Terliakov, PR [20127](https://github.com/python/mypy/pull/20127)) |
| 99 | +- Fix IsADirectoryError for namespace packages when using --linecoverage-report (wyattscarpenter, PR [20109](https://github.com/python/mypy/pull/20109)) |
| 100 | +- Fix an internal error when creating cobertura output for namespace package (wyattscarpenter, PR [20112](https://github.com/python/mypy/pull/20112)) |
| 101 | +- Allow type parameters reusing the name missing from current module (Stanislav Terliakov, PR [20081](https://github.com/python/mypy/pull/20081)) |
| 102 | +- Prevent TypeGuardedType leak from narrowing declared type as part of type variable bound (Stanislav Terliakov, PR [20046](https://github.com/python/mypy/pull/20046)) |
| 103 | +- Fix crash on invalid unpack in base class (Ivan Levkivskyi, PR [19962](https://github.com/python/mypy/pull/19962)) |
| 104 | +- Traverse ParamSpec prefix where we should (Ivan Levkivskyi, PR [19800](https://github.com/python/mypy/pull/19800)) |
| 105 | +- Fix daemon crash related to imports (Ivan Levkivskyi, PR [20271](https://github.com/python/mypy/pull/20271)) |
| 106 | + |
| 107 | +### Mypyc: Support for `__getattr__`, `__setattr__`, and `__delattr__` |
| 108 | + |
| 109 | +Mypyc now has partial support for `__getattr__`, `__setattr__` and |
| 110 | +`__delattr__` methods in native classes. |
| 111 | + |
| 112 | +Note that native attributes are not stored using `__dict__`. Setting attributes |
| 113 | +directly while bypassing `__setattr__` is possible by using |
| 114 | +`super().__setattr__(...)` or `object.__setattr__(...)`, but not via `__dict__`. |
| 115 | + |
| 116 | +Example: |
| 117 | +```python |
| 118 | +class Demo: |
| 119 | + _data: dict[str, str] |
| 120 | + |
| 121 | + def __init__(self) -> None: |
| 122 | + # Initialize data dict without calling our __setattr__ |
| 123 | + super().__setattr__("_data", {}) |
| 124 | + |
| 125 | + def __setattr__(self, name: str, value: str) -> None: |
| 126 | + print(f"Setting {name} = {value!r}") |
| 127 | + |
| 128 | + if name == "_data": |
| 129 | + raise AttributeError("'_data' cannot be set") |
| 130 | + |
| 131 | + self._data[name] = value |
| 132 | + |
| 133 | + def __getattr__(self, name: str) -> str: |
| 134 | + print(f"Getting {name}") |
| 135 | + |
| 136 | + try: |
| 137 | + return self._data[name] |
| 138 | + except KeyError: |
| 139 | + raise AttributeError(name) |
| 140 | + |
| 141 | +d = Demo() |
| 142 | +d.x = "hello" |
| 143 | +d.y = "world" |
| 144 | + |
| 145 | +print(d.x) |
| 146 | +print(d.y) |
| 147 | +``` |
| 148 | + |
| 149 | +Related PRs: |
| 150 | +- Generate `__setattr__` wrapper (Piotr Sawicki, PR [19937](https://github.com/python/mypy/pull/19937)) |
| 151 | +- Generate `__getattr__` wrapper (Piotr Sawicki, PR [19909](https://github.com/python/mypy/pull/19909)) |
| 152 | +- Support deleting attributes in `__setattr__` wrapper (Piotr Sawicki, PR [19997](https://github.com/python/mypy/pull/19997)) |
| 153 | + |
| 154 | +### Miscellaneous Mypyc Improvements |
| 155 | +- Fix `__new__` in native classes with inheritance (Piotr Sawicki, PR [20302](https://github.com/python/mypy/pull/20302)) |
| 156 | +- Fix crash on `super` in generator (Ivan Levkivskyi, PR [20291](https://github.com/python/mypy/pull/20291)) |
| 157 | +- Fix calling base class async method using `super()` (Jukka Lehtosalo, PR [20254](https://github.com/python/mypy/pull/20254)) |
| 158 | +- Fix async or generator methods in traits (Jukka Lehtosalo, PR [20246](https://github.com/python/mypy/pull/20246)) |
| 159 | +- Optimize equality check with string literals (BobTheBuidler, PR [19883](https://github.com/python/mypy/pull/19883)) |
| 160 | +- Fix inheritance of async defs (Jukka Lehtosalo, PR [20044](https://github.com/python/mypy/pull/20044)) |
| 161 | +- Reject invalid `mypyc_attr` args (BobTheBuidler, PR [19963](https://github.com/python/mypy/pull/19963)) |
| 162 | +- Optimize `isinstance` with tuple of primitive types (BobTheBuidler, PR [19949](https://github.com/python/mypy/pull/19949)) |
| 163 | +- Optimize away first index check in for loops if length > 1 (BobTheBuidler, PR [19933](https://github.com/python/mypy/pull/19933)) |
| 164 | +- Fix broken exception/cancellation handling in async def (Jukka Lehtosalo, PR [19951](https://github.com/python/mypy/pull/19951)) |
| 165 | +- Transform `object.__new__` inside `__new__` (Piotr Sawicki, PR [19866](https://github.com/python/mypy/pull/19866)) |
| 166 | +- Fix crash with NewType and other non-class types in incremental builds (Jukka Lehtosalo, PR [19837](https://github.com/python/mypy/pull/19837)) |
| 167 | +- Optimize container creation from expressions with length known at compile time (BobTheBuidler, PR [19503](https://github.com/python/mypy/pull/19503)) |
| 168 | +- Allow per-class free list to be used with inheritance (Jukka Lehtosalo, PR [19790](https://github.com/python/mypy/pull/19790)) |
| 169 | +- Fix object finalization (Marc Mueller, PR [19749](https://github.com/python/mypy/pull/19749)) |
| 170 | +- Allow defining a single-item free "list" for a native class (Jukka Lehtosalo, PR [19785](https://github.com/python/mypy/pull/19785)) |
| 171 | +- Speed up unary "not" (Jukka Lehtosalo, PR [19774](https://github.com/python/mypy/pull/19774)) |
| 172 | + |
| 173 | +### Stubtest Improvements |
| 174 | +- Check `_value_` for ellipsis-valued stub enum members (Stanislav Terliakov, PR [19760](https://github.com/python/mypy/pull/19760)) |
| 175 | +- Include function name in overload assertion messages (Joren Hammudoglu, PR [20063](https://github.com/python/mypy/pull/20063)) |
| 176 | +- Fix special case in analyzing function signature (iap, PR [19822](https://github.com/python/mypy/pull/19822)) |
| 177 | +- Improve `allowlist` docs with better example (sobolevn, PR [20007](https://github.com/python/mypy/pull/20007)) |
| 178 | + |
| 179 | +### Documentation Updates |
| 180 | +- Update duck type compatibility: mention strict-bytes and mypy 2.0 (wyattscarpenter, PR [20121](https://github.com/python/mypy/pull/20121)) |
| 181 | +- Document `--enable-incomplete-feature TypeForm` (wyattscarpenter, PR [20173](https://github.com/python/mypy/pull/20173)) |
| 182 | +- Change the inline TypedDict example (wyattscarpenter, PR [20172](https://github.com/python/mypy/pull/20172)) |
| 183 | +- Replace `List` with built‑in `list` (PEP 585) (Thiago J. Barbalho, PR [20000](https://github.com/python/mypy/pull/20000)) |
| 184 | +- Improve junit documentation (wyattscarpenter, PR [19867](https://github.com/python/mypy/pull/19867)) |
| 185 | + |
| 186 | +### Other Notable Fixes and Improvements |
| 187 | +- Fix annotated with function as type keyword list parameter (KarelKenens, PR [20094](https://github.com/python/mypy/pull/20094)) |
| 188 | +- Fix errors for raise NotImplemented (Shantanu, PR [20168](https://github.com/python/mypy/pull/20168)) |
| 189 | +- Don't let help formatter line-wrap URLs (Frank Dana, PR [19825](https://github.com/python/mypy/pull/19825)) |
| 190 | +- Do not cache fast container types inside lambdas (Stanislav Terliakov, PR [20166](https://github.com/python/mypy/pull/20166)) |
| 191 | +- Respect force-union-syntax flag in error hint (Marc Mueller, PR [20165](https://github.com/python/mypy/pull/20165)) |
| 192 | +- Fix type checking of dict type aliases (Shantanu, PR [20170](https://github.com/python/mypy/pull/20170)) |
| 193 | +- Use pretty callable formatting more often for callable expressions (Theodore Ando, PR [20128](https://github.com/python/mypy/pull/20128)) |
| 194 | +- Use dummy concrete type instead of `Any` when checking protocol variance (bzoracler, PR [20110](https://github.com/python/mypy/pull/20110)) |
| 195 | +- PEP 696: Fix swapping TypeVars with defaults (Randolf Scholz, PR [19449](https://github.com/python/mypy/pull/19449)) |
| 196 | +- Fix narrowing of class pattern with union type (Randolf Scholz, PR [19517](https://github.com/python/mypy/pull/19517)) |
| 197 | +- Do not emit unreachable warnings for lines that return `NotImplemented` (Christoph Tyralla, PR [20083](https://github.com/python/mypy/pull/20083)) |
| 198 | +- Fix matching against `typing.Callable` and `Protocol` types (Randolf Scholz, PR [19471](https://github.com/python/mypy/pull/19471)) |
| 199 | +- Make `--pretty` work better on multi-line issues (A5rocks, PR [20056](https://github.com/python/mypy/pull/20056)) |
| 200 | +- More precise return types for `TypedDict.get` (Randolf Scholz, PR [19897](https://github.com/python/mypy/pull/19897)) |
| 201 | +- 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)) |
| 202 | +- Check class references to catch non-existent classes in match cases (A5rocks, PR [20042](https://github.com/python/mypy/pull/20042)) |
| 203 | +- Do not sort unused error codes in unused error codes warning (wyattscarpenter, PR [20036](https://github.com/python/mypy/pull/20036)) |
| 204 | +- Fix `[name-defined]` false positive in `class A[X, Y=X]:` case (sobolevn, PR [20021](https://github.com/python/mypy/pull/20021)) |
| 205 | +- Filter SyntaxWarnings during AST parsing (Marc Mueller, PR [20023](https://github.com/python/mypy/pull/20023)) |
| 206 | +- Make untyped decorator its own error code (wyattscarpenter, PR [19911](https://github.com/python/mypy/pull/19911)) |
| 207 | +- Support error codes from plugins in options (Sigve Sebastian Farstad, PR [19719](https://github.com/python/mypy/pull/19719)) |
| 208 | +- Allow returning Literals in `__new__` (James Hilton-Balfe, PR [15687](https://github.com/python/mypy/pull/15687)) |
| 209 | +- Inverse interface freshness logic (Ivan Levkivskyi, PR [19809](https://github.com/python/mypy/pull/19809)) |
| 210 | +- Do not report exhaustive-match after deferral (Stanislav Terliakov, PR [19804](https://github.com/python/mypy/pull/19804)) |
| 211 | +- Make `untyped_calls_exclude` invalidate cache (Ivan Levkivskyi, PR [19801](https://github.com/python/mypy/pull/19801)) |
| 212 | +- Add await to empty context hack (Stanislav Terliakov, PR [19777](https://github.com/python/mypy/pull/19777)) |
| 213 | +- Consider non-empty enums assignable to Self (Stanislav Terliakov, PR [19779](https://github.com/python/mypy/pull/19779)) |
| 214 | + |
| 215 | +### Typeshed updates |
| 216 | + |
| 217 | +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. |
| 218 | + |
| 219 | +### Acknowledgements |
| 220 | + |
| 221 | +Thanks to all mypy contributors who contributed to this release: |
| 222 | +- A5rocks |
| 223 | +- BobTheBuidler |
| 224 | +- bzoracler |
| 225 | +- Chainfire |
| 226 | +- Christoph Tyralla |
| 227 | +- David Foster |
| 228 | +- Frank Dana |
| 229 | +- Guo Ci |
| 230 | +- iap |
| 231 | +- Ivan Levkivskyi |
| 232 | +- James Hilton-Balfe |
| 233 | +- jhance |
| 234 | +- Joren Hammudoglu |
| 235 | +- Jukka Lehtosalo |
| 236 | +- KarelKenens |
| 237 | +- Kevin Kannammalil |
| 238 | +- Marc Mueller |
| 239 | +- Michael Carlstrom |
| 240 | +- Michael J. Sullivan |
| 241 | +- Piotr Sawicki |
| 242 | +- Randolf Scholz |
| 243 | +- Shantanu |
| 244 | +- Sigve Sebastian Farstad |
| 245 | +- sobolevn |
| 246 | +- Stanislav Terliakov |
| 247 | +- Stephen Morton |
| 248 | +- Theodore Ando |
| 249 | +- Thiago J. Barbalho |
| 250 | +- wyattscarpenter |
| 251 | + |
| 252 | +I’d also like to thank my employer, Dropbox, for supporting mypy development. |
| 253 | + |
5 | 254 | ## Mypy 1.18.1 |
6 | 255 |
|
7 | 256 | We’ve just uploaded mypy 1.18.1 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)). |
|
0 commit comments