From 16a1163c1c3fd6c930a69f618bf38ac60591cc53 Mon Sep 17 00:00:00 2001 From: Valentin Stanciu <250871+svalentin@users.noreply.github.com> Date: Tue, 17 Dec 2024 17:18:41 +0000 Subject: [PATCH 1/5] Update changelog for release 1.14 --- CHANGELOG.md | 202 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8208fb48294..2d24f286eb0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ ## Next release +... + +## Mypy 1.14 (unreleased) + +We’ve just uploaded mypy 1.14 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)). Mypy is a static type +checker for Python. This release includes new features, performance improvements and bug fixes. +You can install it as follows: + + python3 -m pip install -U mypy + +You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io). + ### Change to enum membership semantics As per the updated [typing specification for enums](https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members), @@ -42,6 +54,196 @@ class Pet(Enum): Contributed by Terence Honles in PR [17207](https://github.com/python/mypy/pull/17207) and Shantanu Jain in PR [18068](https://github.com/python/mypy/pull/18068). +### Added support for @deprecated decorator (PEP 702) + +Mypy can now issue errors or notes when code imports a deprecated feature +explicitly with a `from mod import depr` statement, uses a deprecated feature +imported otherwise or defined locally. Features are considered deprecated when +decorated with `warnings.deprecated`, as specified in [PEP 702](https://peps.python.org/pep-0702). + +You can enable the error code via `--enable-error-code=deprecated` on the mypy +command line or `enable_error_code = deprecated` in the mypy config file. +Use the option `--report-deprecated-as-note` to turn all such errors into notes. + +Will be enabled by default in a future mypy version. + +Contributed by Christoph Tyralla + +List of changes: + + * PEP 702 (@deprecated): descriptors (Christoph Tyralla, PR [18090](https://github.com/python/mypy/pull/18090)) + * Make "deprecated" Note a standard Error, disabled by default (Valentin Stanciu, PR [18192](https://github.com/python/mypy/pull/18192)) + * PEP 702 (@deprecated): consider all possible type positions (Christoph Tyralla, PR [17926](https://github.com/python/mypy/pull/17926)) + * PEP 702 (@deprecated): improve the handling of explicit type annotations of assignment statements (Christoph Tyralla, PR [17899](https://github.com/python/mypy/pull/17899)) + * Add basic support for PEP 702 (@deprecated). (Christoph Tyralla, PR [17476](https://github.com/python/mypy/pull/17476)) + + +### Mypyc Improvements + + * [mypyc] Document optimized bytes ops and additional str ops (Jukka Lehtosalo, PR [18242](https://github.com/python/mypy/pull/18242)) + * [mypyc] Add primitives and specialization for ord() (Jukka Lehtosalo, PR [18240](https://github.com/python/mypy/pull/18240)) + * [mypyc] Make exception type check in assertRaises test helper precise (Jukka Lehtosalo, PR [18241](https://github.com/python/mypy/pull/18241)) + * [mypyc] Optimize str.encode with specializations for common used encodings (Valentin Stanciu, PR [18232](https://github.com/python/mypy/pull/18232)) + * [mypyc] Refactor: use new-style primitives for unary and method ops (Jukka Lehtosalo, PR [18230](https://github.com/python/mypy/pull/18230)) + * [mypyc] Fixing condition to fall back to PyCall for staticmethod and classmethod (Advait Dixit, PR [18228](https://github.com/python/mypy/pull/18228)) + * [mypyc] Refactor: use new-style primitives for unary ops (Jukka Lehtosalo, PR [18213](https://github.com/python/mypy/pull/18213)) + * [mypyc] Refactor: use new-style primitives for function ops (Jukka Lehtosalo, PR [18211](https://github.com/python/mypy/pull/18211)) + * [mypyc] Support unicode surrogates in string literals (Jukka Lehtosalo, PR [18209](https://github.com/python/mypy/pull/18209)) + * [mypyc] Fixing index variable in for-loop with builtins.enumerate. (Advait Dixit, PR [18202](https://github.com/python/mypy/pull/18202)) + * [mypyc] Fixing check for enum classes. (Advait Dixit, PR [18178](https://github.com/python/mypy/pull/18178)) + * [mypyc] Loading type from imported modules. (Advait Dixit, PR [18158](https://github.com/python/mypy/pull/18158)) + * [mypyc] Fix is_native_ref_expr for class attrs (Jared Hance, PR [18031](https://github.com/python/mypy/pull/18031)) + * [mypyc] fix name generation for modules with similar full names (aatle, PR [18001](https://github.com/python/mypy/pull/18001)) + * [mypyc] fix relative imports in __init__.py (Shantanu, PR [17979](https://github.com/python/mypy/pull/17979)) + * [mypyc] Optimize dunder methods (jairov4, PR [17934](https://github.com/python/mypy/pull/17934)) + * [mypyc] Replace deprecated _PyDict_GetItemStringWithError (Marc Mueller, PR [17930](https://github.com/python/mypy/pull/17930)) + * [mypyc] Fix wheel build for cp313-win (Marc Mueller, PR [17941](https://github.com/python/mypy/pull/17941)) + * [mypyc] Use PyGen_GetCode in gen_is_coroutine (Marc Mueller, PR [17931](https://github.com/python/mypy/pull/17931)) + * [mypyc] Optimize calls to final classes (jairov4, PR [17886](https://github.com/python/mypy/pull/17886)) + * [mypyc] Support ellipsis (...) expressions in class bodies (Newbyte, PR [17923](https://github.com/python/mypy/pull/17923)) + * [mypyc] Sync pythoncapi_compat.h (Marc Mueller, PR [17929](https://github.com/python/mypy/pull/17929)) + * [mypyc] Add "runtests.py mypyc-fast" for running fast mypyc tests (Jukka Lehtosalo, PR [17906](https://github.com/python/mypy/pull/17906)) + * [mypyc] Make C unit tests faster by compiling with -O0 (Jukka Lehtosalo, PR [17884](https://github.com/python/mypy/pull/17884)) + +### Stubgen improvements + + * stubgen: do not include mypy generated symbols (Ali Hamdan, PR [18137](https://github.com/python/mypy/pull/18137)) + * stubgen: fix FunctionContext.fullname for nested classes (Chad Dombrova, PR [17963](https://github.com/python/mypy/pull/17963)) + * stubgen: Add flagfile support (Ruslan Sayfutdinov, PR [18061](https://github.com/python/mypy/pull/18061)) + * stubgen: add support for PEPs 695 and 696 syntax (Ali Hamdan, PR [18054](https://github.com/python/mypy/pull/18054)) + +### Stubtest improvements + + * allow the use of --show-traceback and --pdb with stubtest (Stephen Morton, PR [18037](https://github.com/python/mypy/pull/18037)) + * [stubtest] Verify __all__ exists in stub (Sebastian Rittau, PR [18005](https://github.com/python/mypy/pull/18005)) + * stubtest: Stop telling people to use double underscores (Jelle Zijlstra, PR [17897](https://github.com/python/mypy/pull/17897)) + +### Documentation Updates + + * Fixed typo in extending mypy docs. (Carlton Gibson, PR [18234](https://github.com/python/mypy/pull/18234)) + * Update `config_file` docs (sobolevn, PR [18103](https://github.com/python/mypy/pull/18103)) + * Update for Windows platform. Resolves #18096 (ag-tafe, PR [18097](https://github.com/python/mypy/pull/18097)) + * Correct note about `--disallow-any-generics` flag in docs (Abel Sen, PR [18055](https://github.com/python/mypy/pull/18055)) + * Further caution against `--follow-imports=skip` (Shantanu, PR [18048](https://github.com/python/mypy/pull/18048)) + * [docs] fix broken markup in `type_narrowing.rst` (vasiliy, PR [18028](https://github.com/python/mypy/pull/18028)) + * [docs] automatic copyright year update (chiri, PR [17982](https://github.com/python/mypy/pull/17982)) + * [docs] fix the edit page buttton link in docs (Kanishk Pachauri, PR [17933](https://github.com/python/mypy/pull/17933)) + +### Other Notables Fixes and Improvements + + * Implement flag to allow typechecking of untyped modules (Jannick Kremer, PR [17712](https://github.com/python/mypy/pull/17712)) + * Show Protocol __call__ for arguments with incompatible types (MechanicalConstruct, PR [18214](https://github.com/python/mypy/pull/18214)) + * Make join and meet symmetric with strict_optional (MechanicalConstruct, PR [18227](https://github.com/python/mypy/pull/18227)) + * Preserve block unreachablility when checking function definitions with constrained TypeVars (Brian Schubert, PR [18217](https://github.com/python/mypy/pull/18217)) + * Do not include non-init fields in the synthesized `__replace__` method for dataclasses (Victorien, PR [18221](https://github.com/python/mypy/pull/18221)) + * Disallow `TypeVar` constraints parameterized by type variables (Brian Schubert, PR [18186](https://github.com/python/mypy/pull/18186)) + * Refactor: merge duplicate HasTypeVars query visitors (Brian Schubert, PR [18222](https://github.com/python/mypy/pull/18222)) + * Always complain about invalid varargs and varkwargs (Shantanu, PR [18207](https://github.com/python/mypy/pull/18207)) + * Set default strict_optional state to True (Shantanu, PR [18198](https://github.com/python/mypy/pull/18198)) + * Preserve typevar default None in type alias (Sukhorosov Aleksey, PR [18197](https://github.com/python/mypy/pull/18197)) + * Added checks for invalid usage of continue/break/return in except* block (coldwolverine, PR [18132](https://github.com/python/mypy/pull/18132)) + * Do not consider bare TypeVar not overlapping with None for reachability analysis (Stanislav Terliakov, PR [18138](https://github.com/python/mypy/pull/18138)) + * Special case types.DynamicClassAttribute as property-like (Stephen Morton, PR [18150](https://github.com/python/mypy/pull/18150)) + * Disallow bare `ParamSpec` in type aliases (Brian Schubert, PR [18174](https://github.com/python/mypy/pull/18174)) + * Move long_description metadata to pyproject.toml (Marc Mueller, PR [18172](https://github.com/python/mypy/pull/18172)) + * Support `==`-based narrowing of Optional (Christoph Tyralla, PR [18163](https://github.com/python/mypy/pull/18163)) + * Allow TypedDict assignment of Required item to NotRequired ReadOnly item (Brian Schubert, PR [18164](https://github.com/python/mypy/pull/18164)) + * Allow nesting of Annotated with TypedDict special forms inside TypedDicts (Brian Schubert, PR [18165](https://github.com/python/mypy/pull/18165)) + * Infer generic type arguments for slice expressions (Brian Schubert, PR [18160](https://github.com/python/mypy/pull/18160)) + * Fix checking of match sequence pattern against bounded type variables (Brian Schubert, PR [18091](https://github.com/python/mypy/pull/18091)) + * Fix incorrect truthyness for Enum types and literals (David Salvisberg, PR [17337](https://github.com/python/mypy/pull/17337)) + * Move static project metadata to pyproject.toml (Marc Mueller, PR [18146](https://github.com/python/mypy/pull/18146)) + * Fallback to stdlib json if integer exceeds 64-bit range (q0w, PR [18148](https://github.com/python/mypy/pull/18148)) + * Fix `OR` pattern structural matching exhaustiveness (yihong, PR [18119](https://github.com/python/mypy/pull/18119)) + * Fix type inference of positional parameter in class pattern involving builtin subtype (Brian Schubert, PR [18141](https://github.com/python/mypy/pull/18141)) + * Fix [override] error with no line number when argument node has no line number (Brian Schubert, PR [18122](https://github.com/python/mypy/pull/18122)) + * Fix typos in `generics.rst` (yihong, PR [18110](https://github.com/python/mypy/pull/18110)) + * Fix couple crashes in dmypy (Ivan Levkivskyi, PR [18098](https://github.com/python/mypy/pull/18098)) + * Fix subtyping between Instance and Overloaded (Shantanu, PR [18102](https://github.com/python/mypy/pull/18102)) + * Clean up new_semantic_analyzer config (Shantanu, PR [18071](https://github.com/python/mypy/pull/18071)) + * Issue warning for enum with no members in stub (Shantanu, PR [18068](https://github.com/python/mypy/pull/18068)) + * Fix enum attributes are not members (Terence Honles, PR [17207](https://github.com/python/mypy/pull/17207)) + * Fix crash when checking slice expression with step 0 in tuple index (Brian Schubert, PR [18063](https://github.com/python/mypy/pull/18063)) + * Allow union-with-callable attributes to be overridden by methods (Brian Schubert, PR [18018](https://github.com/python/mypy/pull/18018)) + * Emit `[mutable-override]` for covariant override of attribute with method (Brian Schubert, PR [18058](https://github.com/python/mypy/pull/18058)) + * Support ParamSpec mapping with functools.partial (Stanislav Terliakov, PR [17355](https://github.com/python/mypy/pull/17355)) + * Fix approved stub ignore, remove normpath (Shantanu, PR [18045](https://github.com/python/mypy/pull/18045)) + * Make `disallow-any-unimported` flag invertible (Séamus Ó Ceanainn, PR [18030](https://github.com/python/mypy/pull/18030)) + * Filter to possible package paths before trying to resolve a module (falsedrow, PR [18038](https://github.com/python/mypy/pull/18038)) + * Refactor type narrowing further (Jukka Lehtosalo, PR [18043](https://github.com/python/mypy/pull/18043)) + * Refactor "==" and "is" type narrowing logic (Jukka Lehtosalo, PR [18042](https://github.com/python/mypy/pull/18042)) + * Fix overlap check for ParamSpec types (Jukka Lehtosalo, PR [18040](https://github.com/python/mypy/pull/18040)) + * Do not prioritize ParamSpec signatures during overload resolution (Stanislav Terliakov, PR [18033](https://github.com/python/mypy/pull/18033)) + * Fix ternary union for literals (Ivan Levkivskyi, PR [18023](https://github.com/python/mypy/pull/18023)) + * Improve for loop index variable type narrowing (Marc Mueller, PR [18014](https://github.com/python/mypy/pull/18014)) + * Fix compatibility checks for conditional function definitions using decorators (Brian Schubert, PR [18020](https://github.com/python/mypy/pull/18020)) + * Add timeout-minutes to ci config (Marc Mueller, PR [18003](https://github.com/python/mypy/pull/18003)) + * Add initial support for new style TypeVar defaults (PEP 696) (Marc Mueller, PR [17985](https://github.com/python/mypy/pull/17985)) + * TypeGuard should be bool not Any when matching TypeVar (Evgeniy Slobodkin, PR [17145](https://github.com/python/mypy/pull/17145)) + * Fix cache-convert (Shantanu, PR [17974](https://github.com/python/mypy/pull/17974)) + * Fix generator comprehension in meet.py (Shantanu, PR [17969](https://github.com/python/mypy/pull/17969)) + * fix crash issue when using shadowfile with pretty #17853 (Max Chang, PR [17894](https://github.com/python/mypy/pull/17894)) + * [PEP 695] Fix multiple nested classes don't work (Max Chang, PR [17820](https://github.com/python/mypy/pull/17820)) + * Better error for `mypy -p package` without py.typed (Joe Gordon, PR [17908](https://github.com/python/mypy/pull/17908)) + * Emit error for "raise NotImplemented" (Brian Schubert, PR [17890](https://github.com/python/mypy/pull/17890)) + * Add is_lvalue attribute to AttributeContext (Brian Schubert, PR [17881](https://github.com/python/mypy/pull/17881)) + +### Acknowledgements + +Thanks to all mypy contributors who contributed to this release: + +- aatle +- Abel Sen +- Advait Dixit +- ag-tafe +- Alex Waygood +- Ali Hamdan +- Brian Schubert +- Carlton Gibson +- Chad Dombrova +- Chelsea Durazo +- chiri +- Christoph Tyralla +- coldwolverine +- David Salvisberg +- Ekin Dursun +- Evgeniy Slobodkin +- falsedrow +- Gaurav Giri +- Ihor +- Ivan Levkivskyi +- jairov4 +- Jannick Kremer +- Jelle Zijlstra +- jhance +- jianghuyiyuan +- Joe Gordon +- John Doknjas +- Jukka Lehtosalo +- Jukka Lehtosalo +- Kanishk Pachauri +- Marc Mueller +- Max Chang +- MechanicalConstruct +- Newbyte +- q0w +- Ruslan Sayfutdinov +- Sebastian Rittau +- Shantanu +- sobolevn +- Stanislav Terliakov +- Stephen Morton +- Sukhorosov Aleksey +- Séamus Ó Ceanainn +- Terence Honles +- Valentin Stanciu +- vasiliy +- Victorien +- yihong + +I’d also like to thank my employer, Dropbox, for supporting mypy development. + + ## Mypy 1.13 We’ve just uploaded mypy 1.13 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)). From 83fbb22d08d7067596e2efd0ad750f2fb8016e28 Mon Sep 17 00:00:00 2001 From: Valentin Stanciu <250871+svalentin@users.noreply.github.com> Date: Tue, 17 Dec 2024 17:41:27 +0000 Subject: [PATCH 2/5] remove duplicate contributor --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d24f286eb0b..f7bcff2487fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -220,7 +220,6 @@ Thanks to all mypy contributors who contributed to this release: - Joe Gordon - John Doknjas - Jukka Lehtosalo -- Jukka Lehtosalo - Kanishk Pachauri - Marc Mueller - Max Chang From 57b613b4ed4242ac8c51f9f84d5e9d61a30551c3 Mon Sep 17 00:00:00 2001 From: Valentin Stanciu <250871+svalentin@users.noreply.github.com> Date: Wed, 18 Dec 2024 20:28:00 +0000 Subject: [PATCH 3/5] Address comments + section for analyzing untyped modules --- CHANGELOG.md | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7bcff2487fd..721cdfe14a14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ ## Mypy 1.14 (unreleased) We’ve just uploaded mypy 1.14 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)). Mypy is a static type -checker for Python. This release includes new features, performance improvements and bug fixes. +checker for Python. This release includes new features and bug fixes. You can install it as follows: python3 -m pip install -U mypy @@ -57,7 +57,7 @@ Shantanu Jain in PR [18068](https://github.com/python/mypy/pull/18068). ### Added support for @deprecated decorator (PEP 702) Mypy can now issue errors or notes when code imports a deprecated feature -explicitly with a `from mod import depr` statement, uses a deprecated feature +explicitly with a `from mod import depr` statement, or uses a deprecated feature imported otherwise or defined locally. Features are considered deprecated when decorated with `warnings.deprecated`, as specified in [PEP 702](https://peps.python.org/pep-0702). @@ -65,7 +65,7 @@ You can enable the error code via `--enable-error-code=deprecated` on the mypy command line or `enable_error_code = deprecated` in the mypy config file. Use the option `--report-deprecated-as-note` to turn all such errors into notes. -Will be enabled by default in a future mypy version. +Deprecation errors will be enabled by default in a future mypy version. Contributed by Christoph Tyralla @@ -77,6 +77,18 @@ List of changes: * PEP 702 (@deprecated): improve the handling of explicit type annotations of assignment statements (Christoph Tyralla, PR [17899](https://github.com/python/mypy/pull/17899)) * Add basic support for PEP 702 (@deprecated). (Christoph Tyralla, PR [17476](https://github.com/python/mypy/pull/17476)) +### Mypy can be configured to analyze untyped modules + +Mypy normally doesn't analyze imports from modules without stubs or a py.typed marker. +To force mypy to analyze these imports you can now set the `--follow-untyped-imports` command line +flag or the `follow_untyped_imports` config file option to True. This can be set either in the +global section of your mypy config file, or individually on a per-module basis. + +Contributed by Jannick Kremer + +List of changes: + * Implement flag to allow typechecking of untyped modules (Jannick Kremer, PR [17712](https://github.com/python/mypy/pull/17712)) + * Warn about --follow-untyped-imports (Shantanu, PR [18249](https://github.com/python/mypy/pull/18249)) ### Mypyc Improvements @@ -131,8 +143,7 @@ List of changes: ### Other Notables Fixes and Improvements - * Implement flag to allow typechecking of untyped modules (Jannick Kremer, PR [17712](https://github.com/python/mypy/pull/17712)) - * Show Protocol __call__ for arguments with incompatible types (MechanicalConstruct, PR [18214](https://github.com/python/mypy/pull/18214)) + * Show `Protocol` `__call__` for arguments with incompatible types (MechanicalConstruct, PR [18214](https://github.com/python/mypy/pull/18214)) * Make join and meet symmetric with strict_optional (MechanicalConstruct, PR [18227](https://github.com/python/mypy/pull/18227)) * Preserve block unreachablility when checking function definitions with constrained TypeVars (Brian Schubert, PR [18217](https://github.com/python/mypy/pull/18217)) * Do not include non-init fields in the synthesized `__replace__` method for dataclasses (Victorien, PR [18221](https://github.com/python/mypy/pull/18221)) From 8870d4346a7bcf8fc99a0317c28270f8f91ba71b Mon Sep 17 00:00:00 2001 From: Valentin Stanciu <250871+svalentin@users.noreply.github.com> Date: Wed, 18 Dec 2024 21:23:08 +0000 Subject: [PATCH 4/5] Mention mypy config file option `report_deprecated_as_note=True` --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 721cdfe14a14..a87d2c4c0186 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,7 +63,8 @@ decorated with `warnings.deprecated`, as specified in [PEP 702](https://peps.pyt You can enable the error code via `--enable-error-code=deprecated` on the mypy command line or `enable_error_code = deprecated` in the mypy config file. -Use the option `--report-deprecated-as-note` to turn all such errors into notes. +Use the command line flag `--report-deprecated-as-note` or config file option +`report_deprecated_as_note=True` to turn all such errors into notes. Deprecation errors will be enabled by default in a future mypy version. From 093b4a16ffc3b5a7a794bc246ed5744cc6fc4188 Mon Sep 17 00:00:00 2001 From: Valentin Stanciu <250871+svalentin@users.noreply.github.com> Date: Wed, 18 Dec 2024 21:54:06 +0000 Subject: [PATCH 5/5] Add 2 more sections per comments --- CHANGELOG.md | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a87d2c4c0186..c854e18a2f39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,8 @@ ## Mypy 1.14 (unreleased) -We’ve just uploaded mypy 1.14 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)). Mypy is a static type -checker for Python. This release includes new features and bug fixes. +We’ve just uploaded mypy 1.14 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)). +Mypy is a static type checker for Python. This release includes new features and bug fixes. You can install it as follows: python3 -m pip install -U mypy @@ -51,8 +51,8 @@ class Pet(Enum): LION = ... # Member attribute with unknown value and unknown type ``` -Contributed by Terence Honles in PR [17207](https://github.com/python/mypy/pull/17207) and -Shantanu Jain in PR [18068](https://github.com/python/mypy/pull/18068). +Contributed by Terence Honles (PR [17207](https://github.com/python/mypy/pull/17207)) and +Shantanu Jain (PR [18068](https://github.com/python/mypy/pull/18068)). ### Added support for @deprecated decorator (PEP 702) @@ -88,9 +88,46 @@ global section of your mypy config file, or individually on a per-module basis. Contributed by Jannick Kremer List of changes: + * Implement flag to allow typechecking of untyped modules (Jannick Kremer, PR [17712](https://github.com/python/mypy/pull/17712)) * Warn about --follow-untyped-imports (Shantanu, PR [18249](https://github.com/python/mypy/pull/18249)) +### Added support for new style TypeVar Defaults (PEP 696) + +Mypy now supports TypeVar defaults using the new syntax described in PEP 696, that was introduced in Python 3.13. + +```python +@dataclass +class Box[T = int]: + value: T | None = None + +reveal_type(Box()) # type is Box[int], since it's the default +reveal_type(Box(value="Hello World!")) # type is Box[str] +``` + +Contributed by Marc Mueller (PR [17985](https://github.com/python/mypy/pull/17985)) + +### Improved for loop index variable type narrowing + +Mypy now preserves the literal type of index expressions until the next assignment to support `TypedDict` lookups. + +```python +from typing import TypedDict + +class X(TypedDict): + hourly: int + daily: int + +def func(x: X) -> int: + s = 0 + for var in ("hourly", "daily"): + reveal_type(var) # Revealed type is "Union[Literal['hourly']?, Literal['daily']?]" + s += x[var] # x[var] would previously cause a literal-required error + return s +``` + +Contributed by Marc Mueller (PR [18014](https://github.com/python/mypy/pull/18014)) + ### Mypyc Improvements * [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: * Fix overlap check for ParamSpec types (Jukka Lehtosalo, PR [18040](https://github.com/python/mypy/pull/18040)) * Do not prioritize ParamSpec signatures during overload resolution (Stanislav Terliakov, PR [18033](https://github.com/python/mypy/pull/18033)) * Fix ternary union for literals (Ivan Levkivskyi, PR [18023](https://github.com/python/mypy/pull/18023)) - * Improve for loop index variable type narrowing (Marc Mueller, PR [18014](https://github.com/python/mypy/pull/18014)) * Fix compatibility checks for conditional function definitions using decorators (Brian Schubert, PR [18020](https://github.com/python/mypy/pull/18020)) * Add timeout-minutes to ci config (Marc Mueller, PR [18003](https://github.com/python/mypy/pull/18003)) - * Add initial support for new style TypeVar defaults (PEP 696) (Marc Mueller, PR [17985](https://github.com/python/mypy/pull/17985)) * TypeGuard should be bool not Any when matching TypeVar (Evgeniy Slobodkin, PR [17145](https://github.com/python/mypy/pull/17145)) * Fix cache-convert (Shantanu, PR [17974](https://github.com/python/mypy/pull/17974)) * Fix generator comprehension in meet.py (Shantanu, PR [17969](https://github.com/python/mypy/pull/17969))