|
6 | 6 |
|
7 | 7 | ## Mypy 1.14 (unreleased) |
8 | 8 |
|
9 | | -We’ve just uploaded mypy 1.14 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)). Mypy is a static type |
10 | | -checker for Python. This release includes new features and bug fixes. |
| 9 | +We’ve just uploaded mypy 1.14 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)). |
| 10 | +Mypy is a static type checker for Python. This release includes new features and bug fixes. |
11 | 11 | You can install it as follows: |
12 | 12 |
|
13 | 13 | python3 -m pip install -U mypy |
@@ -51,8 +51,8 @@ class Pet(Enum): |
51 | 51 | LION = ... # Member attribute with unknown value and unknown type |
52 | 52 | ``` |
53 | 53 |
|
54 | | -Contributed by Terence Honles in PR [17207](https://github.com/python/mypy/pull/17207) and |
55 | | -Shantanu Jain in PR [18068](https://github.com/python/mypy/pull/18068). |
| 54 | +Contributed by Terence Honles (PR [17207](https://github.com/python/mypy/pull/17207)) and |
| 55 | +Shantanu Jain (PR [18068](https://github.com/python/mypy/pull/18068)). |
56 | 56 |
|
57 | 57 | ### Added support for @deprecated decorator (PEP 702) |
58 | 58 |
|
@@ -88,9 +88,46 @@ global section of your mypy config file, or individually on a per-module basis. |
88 | 88 | Contributed by Jannick Kremer |
89 | 89 |
|
90 | 90 | List of changes: |
| 91 | + |
91 | 92 | * Implement flag to allow typechecking of untyped modules (Jannick Kremer, PR [17712](https://github.com/python/mypy/pull/17712)) |
92 | 93 | * Warn about --follow-untyped-imports (Shantanu, PR [18249](https://github.com/python/mypy/pull/18249)) |
93 | 94 |
|
| 95 | +### Added support for new style TypeVar Defaults (PEP 696) |
| 96 | + |
| 97 | +Mypy now supports TypeVar defaults using the new syntax described in PEP 696, that was introduced in Python 3.13. |
| 98 | + |
| 99 | +```python |
| 100 | +@dataclass |
| 101 | +class Box[T = int]: |
| 102 | + value: T | None = None |
| 103 | + |
| 104 | +reveal_type(Box()) # type is Box[int], since it's the default |
| 105 | +reveal_type(Box(value="Hello World!")) # type is Box[str] |
| 106 | +``` |
| 107 | + |
| 108 | +Contributed by Marc Mueller (PR [17985](https://github.com/python/mypy/pull/17985)) |
| 109 | + |
| 110 | +### Improved for loop index variable type narrowing |
| 111 | + |
| 112 | +Mypy now preserves the literal type of index expressions until the next assignment to support `TypedDict` lookups. |
| 113 | + |
| 114 | +```python |
| 115 | +from typing import TypedDict |
| 116 | + |
| 117 | +class X(TypedDict): |
| 118 | + hourly: int |
| 119 | + daily: int |
| 120 | + |
| 121 | +def func(x: X) -> int: |
| 122 | + s = 0 |
| 123 | + for var in ("hourly", "daily"): |
| 124 | + reveal_type(var) # Revealed type is "Union[Literal['hourly']?, Literal['daily']?]" |
| 125 | + s += x[var] # x[var] would previously cause a literal-required error |
| 126 | + return s |
| 127 | +``` |
| 128 | + |
| 129 | +Contributed by Marc Mueller (PR [18014](https://github.com/python/mypy/pull/18014)) |
| 130 | + |
94 | 131 | ### Mypyc Improvements |
95 | 132 |
|
96 | 133 | * [mypyc] Document optimized bytes ops and additional str ops (Jukka Lehtosalo, PR [18242](https://github.com/python/mypy/pull/18242)) |
@@ -187,10 +224,8 @@ List of changes: |
187 | 224 | * Fix overlap check for ParamSpec types (Jukka Lehtosalo, PR [18040](https://github.com/python/mypy/pull/18040)) |
188 | 225 | * Do not prioritize ParamSpec signatures during overload resolution (Stanislav Terliakov, PR [18033](https://github.com/python/mypy/pull/18033)) |
189 | 226 | * Fix ternary union for literals (Ivan Levkivskyi, PR [18023](https://github.com/python/mypy/pull/18023)) |
190 | | - * Improve for loop index variable type narrowing (Marc Mueller, PR [18014](https://github.com/python/mypy/pull/18014)) |
191 | 227 | * Fix compatibility checks for conditional function definitions using decorators (Brian Schubert, PR [18020](https://github.com/python/mypy/pull/18020)) |
192 | 228 | * Add timeout-minutes to ci config (Marc Mueller, PR [18003](https://github.com/python/mypy/pull/18003)) |
193 | | - * Add initial support for new style TypeVar defaults (PEP 696) (Marc Mueller, PR [17985](https://github.com/python/mypy/pull/17985)) |
194 | 229 | * TypeGuard should be bool not Any when matching TypeVar (Evgeniy Slobodkin, PR [17145](https://github.com/python/mypy/pull/17145)) |
195 | 230 | * Fix cache-convert (Shantanu, PR [17974](https://github.com/python/mypy/pull/17974)) |
196 | 231 | * Fix generator comprehension in meet.py (Shantanu, PR [17969](https://github.com/python/mypy/pull/17969)) |
|
0 commit comments