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
We've just uploaded mypy 2.2.0 to the Python Package Index (PyPI).
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.
Support for Closed TypedDicts (PEP 728)
Mypy now supports closed TypedDicts as specified in PEP 728. A closed TypedDict cannot have extra
keys beyond those explicitly defined. This allows the type checker to determine that certain
operations are safe when they otherwise wouldn't be due to the potential presence of unknown keys.
You can use the closed keyword argument with TypedDict:
HasName=TypedDict("HasName", {"name": str})
HasOnlyName=TypedDict("HasOnlyName", {"name": str}, closed=True)
Movie=TypedDict("Movie", {"name": str, "year": int})
movie: Movie= {"name": "Nimona", "year": 2023}
has_name: HasName=movie# OK: HasName is open (default)has_only_name: HasOnlyName=movie# Error: HasOnlyName is closed and Movie has extra "year" key
Closed TypedDicts enable more precise type checking because the type checker knows exactly which
keys are present. This is particularly useful when working with TypedDict unions or when you want
to ensure that a TypedDict conforms to an exact shape.
The closed keyword also enables safe type narrowing with in checks:
Book=TypedDict('Book', {'book': str}, closed=True)
DVD=TypedDict('DVD', {'dvd': str}, closed=True)
type Inventory=Book|DVDdefprint_type(inventory: Inventory) ->None:
if"book"ininventory:
# Type is narrowed to Book here - safe because DVD is closedprint(inventory["book"])
else:
# Type is narrowed to DVD hereprint(inventory["dvd"])
</tr></table>
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase will rebase this PR
@dependabot recreate will recreate this PR, overwriting any edits that have been made to it
@dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
@dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependenciesPull requests that update a dependency filepython:uvPull requests that update python:uv code
1 participant
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bumps mypy from 2.1.0 to 2.2.0.
Changelog
Sourced from mypy's changelog.
... (truncated)
Commits
b3c4a5bMark release396f508[Chore] Update changelog for 2.2 (#21691)9592a9eUpload wasm wheels to PyPI (#21671)1dc6962Bump ast-serialize to 0.6.0 (#21664)96a7913Bump librt to 0.12.0 (#21663)5ef0902Fix the exportjson tool (.ff cache to .json conversion) (#21628)8d621adSupport --shadow-file with --native-parser (#21623)74ecdd8Sync typeshed (#21612)0cd1541[mypyc] Make function wrappers thread-safe on free-threaded builds (#21620)22a9cfd[mypyc] Make list remove and index thread-safe on free-threaded builds (#21614)Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebasewill rebase this PR@dependabot recreatewill recreate this PR, overwriting any edits that have been made to it@dependabot show <dependency name> ignore conditionswill show all of the ignore conditions of the specified dependency@dependabot ignore this major versionwill close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor versionwill close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependencywill close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)