tag:blogger.com,1999:blog-3958217975838379332025-10-03T09:14:56.174-07:00The Mypy BlogUpdates about mypy, an optional static type checker for PythonJukka Lehtosalohttp://www.blogger.com/profile/00122775610277203624noreply@blogger.comBlogger95125tag:blogger.com,1999:blog-395821797583837933.post-61715043657279382822025-09-11T16:26:00.000-07:002025-09-11T16:26:16.808-07:00Mypy 1.18.1 Released<html>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/a11y-light.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script>hljs.configure({languages:["python","bash"]});hljs.highlightAll();</script>
<body>
<p>We’ve just uploaded mypy 1.18.1 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>).
Mypy is a static type checker for Python. This release includes new features, performance
improvements and bug fixes. You can install it as follows:
<pre><code>python3 -m pip install -U mypy
</code></pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Mypy Performance Improvements</h2>
<p>Mypy 1.18.1 includes numerous performance improvements, resulting in about 40% speedup
compared to 1.17 when type checking mypy itself. In extreme cases, the improvement
can be 10x or higher. The list below is an overview of the various mypy optimizations.
Many mypyc improvements (discussed in a separate section below) also improve performance.
<p>Type caching optimizations have a small risk of causing regressions. When
reporting issues with unexpected inferred types, please also check if
<tt>--disable-expression-cache</tt> will work around the issue, as it turns off some of
these optimizations.
<p><ul>
<li>Improve self check performance by 1.8% (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19768">19768</a>, <a href="https://github.com/python/mypy/pull/19769">19769</a>, <a href="https://github.com/python/mypy/pull/19770">19770</a>)
<li>Optimize fixed-format deserialization (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19765">19765</a>)
<li>Use macros to optimize fixed-format deserialization (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19757">19757</a>)
<li>Two additional micro‑optimizations (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19627">19627</a>)
<li>Another set of micro‑optimizations (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19633">19633</a>)
<li>Cache common types (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19621">19621</a>)
<li>Skip more method bodies in third‑party libraries for speed (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19586">19586</a>)
<li>Simplify the representation of callable types (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19580">19580</a>)
<li>Add cache for types of some expressions (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19505">19505</a>)
<li>Use cache for dictionary expressions (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19536">19536</a>)
<li>Use cache for binary operations (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19523">19523</a>)
<li>Cache types of type objects (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19514">19514</a>)
<li>Avoid duplicate work when checking boolean operations (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19515">19515</a>)
<li>Optimize generic inference passes (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19501">19501</a>)
<li>Speed up the default plugin (Jukka Lehtosalo, PRs <a href="https://github.com/python/mypy/pull/19385">19385</a> and <a href="https://github.com/python/mypy/pull/19462">19462</a>)
<li>Remove nested imports from the default plugin (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19388">19388</a>)
<li>Micro‑optimize type expansion (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19461">19461</a>)
<li>Micro‑optimize type indirection (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19460">19460</a>)
<li>Micro‑optimize the plugin framework (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19464">19464</a>)
<li>Avoid temporary set creation in subtype checking (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19463">19463</a>)
<li>Subtype checking micro‑optimization (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19384">19384</a>)
<li>Return early where possible in subtype check (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19400">19400</a>)
<li>Deduplicate some types before joining (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19409">19409</a>)
<li>Speed up type checking by caching argument inference context (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19323">19323</a>)
<li>Optimize binding method self argument type and deprecation checks (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19556">19556</a>)
<li>Keep trivial instance types/aliases during expansion (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19543">19543</a>)
</ul>
<h2>Fixed‑Format Cache (Experimental)</h2>
<p>Mypy now supports a new cache format used for faster incremental builds. It makes
incremental builds up to twice as fast. The feature is experimental and
currently only supported when using a compiled version of mypy. Use <tt>--fixed-format-cache</tt>
to enable the new format, or <tt>fixed_format_cache = True</tt> in a configuration file.
<p>We plan to enable this by default in a future mypy release, and we'll eventually
deprecate and remove support for the original JSON-based format.
<p>Unlike the JSON-based cache format, the new binary format is currently
not easy to parse and inspect by mypy users. We are planning to provide a tool to
convert fixed-format cache files to JSON, but details of the output JSON may be
different from the current JSON format. If you rely on being able to inspect
mypy cache files, we recommend creating a GitHub issue and explaining your use
case, so that we can more likely provide support for it. (Using
<tt>MypyFile.read(binary_data)</tt> to inspect cache data may be sufficient to support
some use cases.)
<p>This feature was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/19668">19668</a>, <a href="https://github.com/python/mypy/pull/19735">19735</a>, <a href="https://github.com/python/mypy/pull/19750">19750</a>, <a href="https://github.com/python/mypy/pull/19681">19681</a>, <a href="https://github.com/python/mypy/pull/19752">19752</a>, <a href="https://github.com/python/mypy/pull/19815">19815</a>).
<h2>Flexible Variable Definitions: Update</h2>
<p>Mypy 1.16.0 introduced <tt>--allow-redefinition-new</tt>, which allows redefining variables
with different types, and inferring union types for variables from multiple assignments.
The feature is now documented in the <tt>--help</tt> output, but the feature is still experimental.
<p>We are planning to enable this by default in mypy 2.0, and we will also deprecate the
older <tt>--allow-redefinition</tt> flag. Since the new behavior differs significantly from
the older flag, we encourage users of <tt>--allow-redefinition</tt> to experiment with
<tt>--allow-redefinition-new</tt> and create a GitHub issue if the new functionality doesn't
support some important use cases.
<p>This feature was contributed by Jukka Lehtosalo.
<h2>Inferred Type for Bare ClassVar</h2>
<p>A ClassVar without an explicit type annotation now causes the type of the variable
to be inferred from the initializer:
<pre><code class="language-python">from typing import ClassVar
class Item:
# Type of 'next_id' is now 'int' (it was 'Any')
next_id: ClassVar = 1
...
</code></pre>
<p>This feature was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/19573">19573</a>).
<h2>Disjoint Base Classes (@disjoint_base, PEP 800)</h2>
<p>Mypy now understands disjoint bases (PEP 800): it recognizes the <tt>@disjoint_base</tt>
decorator, and rejects class definitions that combine mutually incompatible base classes,
and takes advantage of the fact that such classes cannot exist in reachability and
narrowing logic.
<p>This class definition will now generate an error:
<pre><code class="language-python"># Error: Class "Bad" has incompatible disjoint bases
class Bad(str, Exception):
...
</code></pre>
<p>This feature was contributed by Jelle Zijlstra (PR <a href="https://github.com/python/mypy/pull/19678">19678</a>).
<h2>Miscellaneous New Mypy Features</h2>
<p><ul>
<li>Add <tt>--strict-equality-for-none</tt> to flag non-overlapping comparisons involving None (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/19718">19718</a>)
<li>Don’t show import‑related errors after a module‑level assert such as <tt>assert sys.platform == "linux"</tt> that is always false (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19347">19347</a>)
</ul>
<h2>Improvements to Match Statements</h2>
<p><ul>
<li>Add temporary named expressions for match subjects (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18446">18446</a>)
<li>Fix unwrapping of assignment expressions in match subject (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/19742">19742</a>)
<li>Omit errors for class patterns against object (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/19709">19709</a>)
<li>Remove unnecessary error for certain match class patterns (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/19708">19708</a>)
<li>Use union type for captured vars in or pattern (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/19710">19710</a>)
<li>Prevent final reassignment inside match case (Omer Hadari, PR <a href="https://github.com/python/mypy/pull/19496">19496</a>)
</ul>
<h2>Fixes to Crashes</h2>
<p><ul>
<li>Fix crash with variadic tuple arguments to a generic type (Randolf Scholz, PR <a href="https://github.com/python/mypy/pull/19705">19705</a>)
<li>Fix crash when enable_error_code in pyproject.toml has wrong type (wyattscarpenter, PR <a href="https://github.com/python/mypy/pull/19494">19494</a>)
<li>Prevent crash for dataclass with PEP 695 TypeVarTuple on Python 3.13+ (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19565">19565</a>)
<li>Fix crash on settable property alias (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19615">19615</a>)
</ul>
<h2>Experimental Free-threading Support for Mypyc</h2>
<p>All mypyc tests now pass on free-threading Python 3.14 release candidate builds. The performance
of various micro-benchmarks scale well across multiple threads.
<p>Free-threading support is still experimental. Note that native attribute access
(get and set), list item access and certain other operations are still
unsafe when there are race conditions. This will likely change in the future.
You can follow the
<a href="https://github.com/mypyc/mypyc/issues?q=is%3Aissue%20state%3Aopen%20label%3Aarea-free-threading">area-free-threading label</a>
in the mypyc issues tracker to follow progress.
<p>Related PRs:
<p><ul>
<li>Enable free‑threading when compiling multiple modules (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19541">19541</a>)
<li>Fix <tt>list.pop</tt> on free‑threaded builds (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19522">19522</a>)
<li>Make type objects immortal under free‑threading (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19538">19538</a>)
</ul>
<h2>Mypyc: Support <tt>__new__</tt></h2>
<p>Mypyc now has rudimentary support for user-defined <tt>__new__</tt> methods.
<p>This feature was contributed by Piotr Sawicki (PR <a href="https://github.com/python/mypy/pull/19739">19739</a>).
<h2>Mypyc: Faster Generators and Async Functions</h2>
<p>Generators and calls of async functions are now faster, sometimes by 2x or more.
<p>Related PRs:
<p><ul>
<li>Speed up for loops over native generators (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19415">19415</a>)
<li>Speed up native‑to‑native calls using await (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19398">19398</a>)
<li>Call generator helper directly in await expressions (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19376">19376</a>)
<li>Speed up generator allocation with per‑type freelists (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19316">19316</a>)
</ul>
<h2>Miscellaneous Mypyc Improvements</h2>
<p><ul>
<li>Special‑case certain Enum method calls for speed (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19634">19634</a>)
<li>Fix issues related to subclassing and undefined attribute tracking (Chainfire, PR <a href="https://github.com/python/mypy/pull/19787">19787</a>)
<li>Fix invalid C function signature (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19773">19773</a>)
<li>Speed up implicit <tt>__ne__</tt> (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19759">19759</a>)
<li>Speed up equality with optional str/bytes types (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19758">19758</a>)
<li>Speed up access to empty tuples (BobTheBuidler, PR <a href="https://github.com/python/mypy/pull/19654">19654</a>)
<li>Speed up calls with <tt>*args</tt> (BobTheBuidler, PRs <a href="https://github.com/python/mypy/pull/19623">19623</a> and <a href="https://github.com/python/mypy/pull/19631">19631</a>)
<li>Speed up calls with <tt>**kwargs</tt> (BobTheBuidler, PR <a href="https://github.com/python/mypy/pull/19630">19630</a>)
<li>Optimize <tt>type(x)</tt>, <tt>x.__class__</tt>, and <tt><type>.__name__</tt> (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19691">19691</a>, <a href="https://github.com/python/mypy/pull/19683">19683</a>)
<li>Specialize <tt>bytes.decode</tt> for common encodings (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19688">19688</a>)
<li>Speed up <tt>in</tt> operations using final fixed‑length tuples (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19682">19682</a>)
<li>Optimize f‑string building from final values (BobTheBuidler, PR <a href="https://github.com/python/mypy/pull/19611">19611</a>)
<li>Add dictionary set item for exact dict instances (BobTheBuidler, PR <a href="https://github.com/python/mypy/pull/19657">19657</a>)
<li>Cache length when iterating over immutable types (BobTheBuidler, PR <a href="https://github.com/python/mypy/pull/19656">19656</a>)
<li>Fix name conflict related to attributes of generator classes (Piotr Sawicki, PR <a href="https://github.com/python/mypy/pull/19535">19535</a>)
<li>Fix segfault from heap type objects with a static docstring (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/19636">19636</a>)
<li>Unwrap NewType to its base type for additional optimizations (BobTheBuidler, PR <a href="https://github.com/python/mypy/pull/19497">19497</a>)
<li>Generate an export table only for separate compilation (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19521">19521</a>)
<li>Speed up <tt>isinstance</tt> with built‑in types (Piotr Sawicki, PR <a href="https://github.com/python/mypy/pull/19435">19435</a>)
<li>Use native integers for some sequence indexing (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19426">19426</a>)
<li>Speed up <tt>isinstance(obj, list)</tt> (Piotr Sawicki, PR <a href="https://github.com/python/mypy/pull/19416">19416</a>)
<li>Report error on reserved method names (Piotr Sawicki, PR <a href="https://github.com/python/mypy/pull/19407">19407</a>)
<li>Speed up string equality (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19402">19402</a>)
<li>Raise <tt>NameError</tt> on undefined names (Piotr Sawicki, PR <a href="https://github.com/python/mypy/pull/19395">19395</a>)
<li>Use per‑type freelists for nested functions (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19390">19390</a>)
<li>Simplify comparison of tuple elements (Piotr Sawicki, PR <a href="https://github.com/python/mypy/pull/19396">19396</a>)
<li>Generate introspection signatures for compiled functions (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/19307">19307</a>)
<li>Fix undefined attribute checking special case (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19378">19378</a>)
<li>Fix comparison of tuples with different lengths (Piotr Sawicki, PR <a href="https://github.com/python/mypy/pull/19372">19372</a>)
<li>Speed up <tt>list.clear</tt> (Jahongir Qurbonov, PR <a href="https://github.com/python/mypy/pull/19344">19344</a>)
<li>Speed up <tt>weakref.proxy</tt> (BobTheBuidler, PR <a href="https://github.com/python/mypy/pull/19217">19217</a>)
<li>Speed up <tt>weakref.ref</tt> (BobTheBuidler, PR <a href="https://github.com/python/mypy/pull/19099">19099</a>)
<li>Speed up <tt>str.count</tt> (BobTheBuidler, PR <a href="https://github.com/python/mypy/pull/19264">19264</a>)
</ul>
<h2>Stubtest Improvements</h2>
<p><ul>
<li>Add temporary <tt>--ignore-disjoint-bases</tt> flag to ease PEP 800 migration (Joren Hammudoglu, PR <a href="https://github.com/python/mypy/pull/19740">19740</a>)
<li>Flag redundant uses of <tt>@disjoint_base</tt> (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/19715">19715</a>)
<li>Improve signatures for <tt>__init__</tt> of C extension classes (Stephen Morton, PR <a href="https://github.com/python/mypy/pull/18259">18259</a>)
<li>Handle overloads with mixed positional‑only parameters (Stephen Morton, PR <a href="https://github.com/python/mypy/pull/18287">18287</a>)
<li>Use “parameter” (not “argument”) in error messages (PrinceNaroliya, PR <a href="https://github.com/python/mypy/pull/19707">19707</a>)
<li>Don’t require <tt>@disjoint_base</tt> when <tt>__slots__</tt> imply finality (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/19701">19701</a>)
<li>Allow runtime‑existing aliases of <tt>@type_check_only</tt> types (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/19568">19568</a>)
<li>More detailed checking of type objects in stubtest (Stephen Morton, PR <a href="https://github.com/python/mypy/pull/18251">18251</a>)
<li>Support running stubtest in non-UTF8 terminals (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19085">19085</a>)
</ul>
<h2>Documentation Updates</h2>
<p><ul>
<li>Add idlemypyextension to IDE integrations (CoolCat467, PR <a href="https://github.com/python/mypy/pull/18615">18615</a>)
<li>Document that <tt>object</tt> is often preferable to <tt>Any</tt> in APIs (wyattscarpenter, PR <a href="https://github.com/python/mypy/pull/19103">19103</a>)
<li>Include a detailed listing of flags enabled by <tt>--strict</tt> (wyattscarpenter, PR <a href="https://github.com/python/mypy/pull/19062">19062</a>)
<li>Update “common issues” (reveal_type/reveal_locals; note on orjson) (wyattscarpenter, PR <a href="https://github.com/python/mypy/pull/19059">19059</a>, <a href="https://github.com/python/mypy/pull/19058">19058</a>)
</ul>
<h2>Other Notable Fixes and Improvements</h2>
<p><ul>
<li>Remove deprecated <tt>--new-type-inference</tt> flag (the new algorithm has long been default) (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19570">19570</a>)
<li>Use empty context as a fallback for return expressions when outer context misleads inference (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19767">19767</a>)
<li>Fix forward references in type parameters of over‑parameterized PEP 695 aliases (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/19725">19725</a>)
<li>Don’t expand PEP 695 aliases when checking node fullnames (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/19699">19699</a>)
<li>Don’t use outer context for 'or' expression inference when LHS is Any (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19748">19748</a>)
<li>Recognize buffer protocol special methods (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/19581">19581</a>)
<li>Support attribute access on enum members correctly (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19422">19422</a>)
<li>Check <tt>__slots__</tt> assignments on self types (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19332">19332</a>)
<li>Move self‑argument checks after decorator application (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19490">19490</a>)
<li>Infer empty list for <tt>__slots__</tt> and module <tt>__all__</tt> (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19348">19348</a>)
<li>Use normalized tuples for fallback calculation (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19111">19111</a>)
<li>Preserve literals when joining similar types (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19279">19279</a>)
<li>Allow adjacent conditionally‑defined overloads (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19042">19042</a>)
<li>Check property decorators more strictly (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19313">19313</a>)
<li>Support properties with generic setters (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19298">19298</a>)
<li>Generalize class/static method and property alias support (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19297">19297</a>)
<li>Re‑widen custom properties after narrowing (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19296">19296</a>)
<li>Avoid erasing type objects when checking runtime cover (Shantanu, PR <a href="https://github.com/python/mypy/pull/19320">19320</a>)
<li>Include tuple fallback in constraints built from tuple types (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19100">19100</a>)
<li>Somewhat better isinstance support on old‑style unions (Shantanu, PR <a href="https://github.com/python/mypy/pull/19714">19714</a>)
<li>Improve promotions inside unions (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/19245">19245</a>)
<li>Treat uninhabited types as having all attributes (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19300">19300</a>)
<li>Improve metaclass conflict checks (Robsdedude, PR <a href="https://github.com/python/mypy/pull/17682">17682</a>)
<li>Fixes to metaclass resolution algorithm (Robsdedude, PR <a href="https://github.com/python/mypy/pull/17713">17713</a>)
<li>PEP 702 @deprecated: handle “combined” overloads (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/19626">19626</a>)
<li>PEP 702 @deprecated: include overloads in snapshot descriptions (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/19613">19613</a>)
<li>Ignore overload implementation when checking <tt>__OP__</tt> / <tt>__rOP__</tt> compatibility (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18502">18502</a>)
<li>Support <tt>_value_</tt> as a fallback for ellipsis Enum members (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19352">19352</a>)
<li>Sort arguments in TypedDict overlap messages (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/19666">19666</a>)
<li>Fix handling of implicit return in lambda (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19642">19642</a>)
<li>Improve behavior of uninhabited types (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19648">19648</a>)
<li>Fix overload diagnostics when <tt>*args</tt> and <tt>**kwargs</tt> both match (Shantanu, PR <a href="https://github.com/python/mypy/pull/19614">19614</a>)
<li>Further fix overload diagnostics for <tt>*args</tt>/<tt>**kwargs</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/19619">19619</a>)
<li>Show type variable name in "Cannot infer type argument" (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/19290">19290</a>)
<li>Fail gracefully on unsupported template strings (PEP 750) (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/19700">19700</a>)
<li>Revert colored argparse help for Python 3.14 (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/19721">19721</a>)
<li>Update stubinfo for latest typeshed (Shantanu, PR <a href="https://github.com/python/mypy/pull/19771">19771</a>)
<li>Fix dict assignment when an incompatible same‑shape TypedDict exists (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19592">19592</a>)
<li>Fix constructor type for subclasses of Any (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19295">19295</a>)
<li>Fix TypeGuard/TypeIs being forgotten in some cases (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/19325">19325</a>)
<li>Fix TypeIs negative narrowing for unions of generics (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18193">18193</a>)
<li>dmypy suggest: Fix incorrect signature suggestion when a type matches a module name (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18937">18937</a>)
<li>dmypy suggest: Fix interaction with <tt>__new__</tt> (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18966">18966</a>)
<li>dmypy suggest: Support Callable / callable Protocols in decorator unwrapping (Anthony Sottile, PR <a href="https://github.com/python/mypy/pull/19072">19072</a>)
<li>Fix missing error when redeclaring a type variable in a nested generic class (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18883">18883</a>)
<li>Fix for overloaded type object erasure (Shantanu, PR <a href="https://github.com/python/mypy/pull/19338">19338</a>)
<li>Fix TypeGuard with call on temporary object (Saul Shanabrook, PR <a href="https://github.com/python/mypy/pull/19577">19577</a>)
</ul>
<h2>Typeshed Updates</h2>
<p>Please see <a href="https://github.com/python/typeshed/commits/main?after=2480d7e7c74493a024eaf254c5d2c6f452c80ee2+0&branch=main&path=stdlib">git log</a> for full list of standard library typeshed stub changes.
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<p><ul>
<li>Ali Hamdan
<li>Anthony Sottile
<li>BobTheBuidler
<li>Brian Schubert
<li>Chainfire
<li>Charlie Denton
<li>Christoph Tyralla
<li>CoolCat467
<li>Daniel Hnyk
<li>Emily
<li>Emma Smith
<li>Ethan Sarp
<li>Ivan Levkivskyi
<li>Jahongir Qurbonov
<li>Jelle Zijlstra
<li>Joren Hammudoglu
<li>Jukka Lehtosalo
<li>Marc Mueller
<li>Omer Hadari
<li>Piotr Sawicki
<li>PrinceNaroliya
<li>Randolf Scholz
<li>Robsdedude
<li>Saul Shanabrook
<li>Shantanu
<li>Stanislav Terliakov
<li>Stephen Morton
<li>wyattscarpenter
</ul>
<p>I’d also like to thank my employer, Dropbox, for supporting mypy development.
</body>
</html>Kevin Kannammalilhttp://www.blogger.com/profile/15675437575365183193noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-27357172567498645592025-07-14T13:41:00.000-07:002025-07-14T13:41:44.473-07:00Mypy 1.17 Released<html>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/a11y-light.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script>hljs.configure({languages:["python","bash"]});hljs.highlightAll();</script>
<body>
<p>We’ve just uploaded mypy 1.17 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>).
Mypy is a static type checker for Python. This release includes new features and bug fixes.
You can install it as follows:
<pre><code>python3 -m pip install -U mypy
</code></pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Optionally Check That Match Is Exhaustive</h2>
<p>Mypy can now optionally generate an error if a match statement does not
match exhaustively, without having to use <tt>assert_never(...)</tt>. Enable
this by using <tt>--enable-error-code exhaustive-match</tt>.
<p>Example:
<pre><code class="language-python"># mypy: enable-error-code=exhaustive-match
import enum
class Color(enum.Enum):
RED = 1
BLUE = 2
def show_color(val: Color) -> None:
# error: Unhandled case for values of type "Literal[Color.BLUE]"
match val:
case Color.RED:
print("red")
</code></pre>
<p>This feature was contributed by Donal Burns (PR <a href="https://github.com/python/mypy/pull/19144">19144</a>).
<h2>Further Improvements to Attribute Resolution</h2>
<p>This release includes additional improvements to how attribute types
and kinds are resolved. These fix many bugs and overall improve consistency.
<p><ul>
<li>Handle corner case: protocol/class variable/descriptor (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19277">19277</a>)
<li>Fix a few inconsistencies in protocol/type object interactions (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19267">19267</a>)
<li>Refactor/unify access to static attributes (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19254">19254</a>)
<li>Remove inconsistencies in operator handling (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19250">19250</a>)
<li>Make protocol subtyping more consistent (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18943">18943</a>)
</ul>
<h2>Fixes to Nondeterministic Type Checking</h2>
<p>Previous mypy versions could infer different types for certain expressions
across different runs (typically depending on which order certain types
were processed, and this order was nondeterministic). This release includes
fixes to several such issues.
<p><ul>
<li>Fix nondeterministic type checking by making join with explicit Protocol and type promotion commute (Shantanu, PR <a href="https://github.com/python/mypy/pull/18402">18402</a>)
<li>Fix nondeterministic type checking caused by nonassociative of None joins (Shantanu, PR <a href="https://github.com/python/mypy/pull/19158">19158</a>)
<li>Fix nondeterministic type checking caused by nonassociativity of joins (Shantanu, PR <a href="https://github.com/python/mypy/pull/19147">19147</a>)
<li>Fix nondeterministic type checking by making join between <tt>type</tt> and TypeVar commute (Shantanu, PR <a href="https://github.com/python/mypy/pull/19149">19149</a>)
</ul>
<h2>Remove Support for Targeting Python 3.8</h2>
<p>Mypy now requires <tt>--python-version 3.9</tt> or greater. Support for targeting Python 3.8 is
fully removed now. Since 3.8 is an unsupported version, mypy will default to the oldest
supported version (currently 3.9) if you still try to target 3.8.
<p>This change is necessary because typeshed stopped supporting Python 3.8 after it
reached its End of Life in October 2024.
<p>Contributed by Marc Mueller
(PR <a href="https://github.com/python/mypy/pull/19157">19157</a>, PR <a href="https://github.com/python/mypy/pull/19162">19162</a>).
<h2>Initial Support for Python 3.14</h2>
<p>Mypy is now tested on 3.14 and mypyc works with 3.14.0b3 and later.
Binary wheels compiled with mypyc for mypy itself will be available for 3.14
some time after 3.14.0rc1 has been released.
<p>Note that not all features are supported just yet.
<p>Contributed by Marc Mueller (PR <a href="https://github.com/python/mypy/pull/19164">19164</a>)
<h2>Deprecated Flag: <tt>--force-uppercase-builtins</tt></h2>
<p>Mypy only supports Python 3.9+. The <tt>--force-uppercase-builtins</tt> flag is now
deprecated as unnecessary, and a no-op. It will be removed in a future version.
<p>Contributed by Marc Mueller (PR <a href="https://github.com/python/mypy/pull/19176">19176</a>)
<h2>Mypyc: Improvements to Generators and Async Functions</h2>
<p>This release includes both performance improvements and bug fixes related
to generators and async functions (these share many implementation details).
<p><ul>
<li>Fix exception swallowing in async try/finally blocks with await (Chainfire, PR <a href="https://github.com/python/mypy/pull/19353">19353</a>)
<li>Fix AttributeError in async try/finally with mixed return paths (Chainfire, PR <a href="https://github.com/python/mypy/pull/19361">19361</a>)
<li>Make generated generator helper method internal (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19268">19268</a>)
<li>Free coroutine after await encounters StopIteration (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19231">19231</a>)
<li>Use non-tagged integer for generator label (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19218">19218</a>)
<li>Merge generator and environment classes in simple cases (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19207">19207</a>)
</ul>
<h2>Mypyc: Partial, Unsafe Support for Free Threading</h2>
<p>Mypyc has minimal, quite memory-unsafe support for the free threaded
builds of 3.14. It is also only lightly tested. Bug reports and experience
reports are welcome!
<p>Here are some of the major limitations:
<p><ul>
<li>Free threading only works when compiling a single module at a time.
<li>If there is concurrent access to an object while another thread is mutating the same
</ul>
object, it's possible to encounter segfaults and memory corruption.
<p><ul>
<li>There are no efficient native primitives for thread synthronization, though the
</ul>
regular <tt>threading</tt> module can be used.
<p><ul>
<li>Some workloads don't scale well to multiple threads for no clear reason.
</ul>
<p>Related PRs:
<p><ul>
<li>Enable partial, unsafe support for free-threading (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19167">19167</a>)
<li>Fix incref/decref on free-threaded builds (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19127">19127</a>)
</ul>
<h2>Other Mypyc Fixes and Improvements</h2>
<p><ul>
<li>Derive .c file name from full module name if using multi_file (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19278">19278</a>)
<li>Support overriding the group name used in output files (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19272">19272</a>)
<li>Add note about using non-native class to subclass built-in types (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19236">19236</a>)
<li>Make some generated classes implicitly final (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19235">19235</a>)
<li>Don't simplify module prefixes if using separate compilation (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19206">19206</a>)
</ul>
<h2>Stubgen Improvements</h2>
<p><ul>
<li>Add import for <tt>types</tt> in <tt>__exit__</tt> method signature (Alexey Makridenko, PR <a href="https://github.com/python/mypy/pull/19120">19120</a>)
<li>Add support for including class and property docstrings (Chad Dombrova, PR <a href="https://github.com/python/mypy/pull/17964">17964</a>)
<li>Don't generate <tt>Incomplete | None = None</tt> argument annotation (Sebastian Rittau, PR <a href="https://github.com/python/mypy/pull/19097">19097</a>)
<li>Support several more constructs in stubgen's alias printer (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18888">18888</a>)
</ul>
<h2>Miscellaneous Fixes and Improvements</h2>
<p><ul>
<li>Combine the revealed types of multiple iteration steps in a more robust manner (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/19324">19324</a>)
<li>Improve the handling of "iteration dependent" errors and notes in finally clauses (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/19270">19270</a>)
<li>Lessen dmypy suggest path limitations for Windows machines (CoolCat467, PR <a href="https://github.com/python/mypy/pull/19337">19337</a>)
<li>Fix type ignore comments erroneously marked as unused by dmypy (Charlie Denton, PR <a href="https://github.com/python/mypy/pull/15043">15043</a>)
<li>Fix misspelled <tt>exhaustive-match</tt> error code (johnthagen, PR <a href="https://github.com/python/mypy/pull/19276">19276</a>)
<li>Fix missing error context for unpacking assignment involving star expression (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/19258">19258</a>)
<li>Fix and simplify error de-duplication (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19247">19247</a>)
<li>Disallow <tt>ClassVar</tt> in type aliases (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/19263">19263</a>)
<li>Add script that prints list of compiled files when compiling mypy (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19260">19260</a>)
<li>Fix help message url for "None and Optional handling" section (Guy Wilson, PR <a href="https://github.com/python/mypy/pull/19252">19252</a>)
<li>Display fully qualified name of imported base classes in errors about incompatible overrides (Mikhail Golubev, PR <a href="https://github.com/python/mypy/pull/19115">19115</a>)
<li>Avoid false <tt>unreachable</tt>, <tt>redundant-expr</tt>, and <tt>redundant-casts</tt> warnings in loops more robustly and efficiently, and avoid multiple <tt>revealed type</tt> notes for the same line (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/19118">19118</a>)
<li>Fix type extraction from <tt>isinstance</tt> checks (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19223">19223</a>)
<li>Erase stray type variables in <tt>functools.partial</tt> (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18954">18954</a>)
<li>Make inferring condition value recognize the whole truth table (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18944">18944</a>)
<li>Support type aliases, <tt>NamedTuple</tt> and <tt>TypedDict</tt> in constrained TypeVar defaults (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18884">18884</a>)
<li>Move dataclass <tt>kw_only</tt> fields to the end of the signature (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19018">19018</a>)
<li>Provide a better fallback value for the <tt>python_version</tt> option (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/19162">19162</a>)
<li>Avoid spurious non-overlapping equality error with metaclass with <tt>__eq__</tt> (Michael J. Sullivan, PR <a href="https://github.com/python/mypy/pull/19220">19220</a>)
<li>Narrow type variable bounds (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19183">19183</a>)
<li>Add classifier for Python 3.14 (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/19199">19199</a>)
<li>Capitalize syntax error messages (Charulata, PR <a href="https://github.com/python/mypy/pull/19114">19114</a>)
<li>Infer constraints eagerly if actual is Any (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19190">19190</a>)
<li>Include walrus assignments in conditional inference (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19038">19038</a>)
<li>Use PEP 604 syntax when converting types to strings (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/19179">19179</a>)
<li>Use more lower-case builtin types in error messages (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/19177">19177</a>)
<li>Fix example to use correct method of Stack (Łukasz Kwieciński, PR <a href="https://github.com/python/mypy/pull/19123">19123</a>)
<li>Forbid <tt>.pop</tt> of <tt>Readonly</tt> <tt>NotRequired</tt> TypedDict items (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19133">19133</a>)
<li>Emit a friendlier warning on invalid exclude regex, instead of a stacktrace (wyattscarpenter, PR <a href="https://github.com/python/mypy/pull/19102">19102</a>)
<li>Enable ANSI color codes for dmypy client in Windows (wyattscarpenter, PR <a href="https://github.com/python/mypy/pull/19088">19088</a>)
<li>Extend special case for context-based type variable inference to unions in return position (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18976">18976</a>)
</ul>
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<p><ul>
<li>Alexey Makridenko
<li>Brian Schubert
<li>Chad Dombrova
<li>Chainfire
<li>Charlie Denton
<li>Charulata
<li>Christoph Tyralla
<li>CoolCat467
<li>Donal Burns
<li>Guy Wilson
<li>Ivan Levkivskyi
<li>johnthagen
<li>Jukka Lehtosalo
<li>Łukasz Kwieciński
<li>Marc Mueller
<li>Michael J. Sullivan
<li>Mikhail Golubev
<li>Sebastian Rittau
<li>Shantanu
<li>Stanislav Terliakov
<li>wyattscarpenter
</ul>
<p>I’d also like to thank my employer, Dropbox, for supporting mypy development.
</body>
</html>Ethan Sarphttp://www.blogger.com/profile/16810004377371956662noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-22344650802016579412025-05-29T06:52:00.000-07:002025-05-29T06:52:29.404-07:00Mypy 1.16 Released<html>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/a11y-light.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script>hljs.configure({languages:["python","bash"]});hljs.highlightAll();</script>
<body>
<p>We’ve just uploaded mypy 1.16 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>).
Mypy is a static type checker for Python. This release includes new features and bug fixes.
You can install it as follows:
<pre><code>python3 -m pip install -U mypy
</code></pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Different Property Getter and Setter Types</h2>
<p>Mypy now supports using different types for a property getter and setter:
<pre><code class="language-python">class A:
_value: int
@property
def foo(self) -> int:
return self._value
@foo.setter
def foo(self, x: str | int) -> None:
try:
self._value = int(x)
except ValueError:
raise Exception(f"'{x}' not valid value for 'foo'")
</code></pre>
<p>This was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/18510">18510</a>).
<h2>Flexible Variable Redefinitions (Experimental)</h2>
<p>Mypy now allows unannotated variables to be freely redefined with
different types when using the experimental <tt>--allow-redefinition-new</tt>
flag. You will also need to enable <tt>--local-partial-types</tt>. Mypy will
now infer a union type when different types are assigned to a
variable:
<pre><code class="language-py"># mypy: allow-redefinition-new, local-partial-types
def f(n: int, b: bool) -> int | str:
if b:
x = n
else:
x = str(n)
# Type of 'x' is int | str here.
return x
</code></pre>
<p>Without the new flag, mypy only supports inferring optional types (<tt>X
| None</tt>) from multiple assignments, but now mypy can infer arbitrary
union types.
<p>An unannotated variable can now also have different types in different
code locations:
<pre><code class="language-py"># mypy: allow-redefinition-new, local-partial-types
...
if cond():
for x in range(n):
# Type of 'x' is 'int' here
...
else:
for x in ['a', 'b']:
# Type of 'x' is 'str' here
...
</code></pre>
<p>We are planning to turn this flag on by default in mypy 2.0, along
with <tt>--local-partial-types</tt>. The feature is still experimental and
has known issues, and the semantics may still change in the
future. You may need to update or add type annotations when switching
to the new behavior, but if you encounter anything unexpected, please
create a GitHub issue.
<p>This was contributed by Jukka Lehtosalo
(PR <a href="https://github.com/python/mypy/pull/18727">18727</a>, PR <a href="https://github.com/python/mypy/pull/19153">19153</a>).
<h2>Stricter Type Checking with Imprecise Types</h2>
<p>Mypy can now detect additional errors in code that uses <tt>Any</tt> types or has missing function annotations.
<p>When calling <tt>dict.get(x, None)</tt> on an object of type <tt>dict[str, Any]</tt>, this
now results in an optional type (in the past it was <tt>Any</tt>):
<pre><code class="language-python">def f(d: dict[str, Any]) -> int:
# Error: Return value is "Any | None" but expected "int"
return d.get("x", None)
</code></pre>
<p>Type narrowing using assignments can result in more precise types in
the presence of <tt>Any</tt> types:
<pre><code class="language-python">def foo(): ...
def bar(n: int) -> None:
x = foo()
# Type of 'x' is 'Any' here
if n > 5:
x = str(n)
# Type of 'x' is 'str' here
</code></pre>
<p>When using <tt>--check-untyped-defs</tt>, unannotated overrides are now
checked more strictly against superclass definitions.
<p>Related PRs:
<p><ul>
<li>Use union types instead of join in binder (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18538">18538</a>)
<li>Check superclass compatibility of untyped methods if <tt>--check-untyped-defs</tt> is set (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18970">18970</a>)
</ul>
<h2>Improvements to Attribute Resolution</h2>
<p>This release includes several fixes to inconsistent resolution of attribute, method and descriptor types.
<p><ul>
<li>Consolidate descriptor handling (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18831">18831</a>)
<li>Make multiple inheritance checking use common semantics (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18876">18876</a>)
<li>Make method override checking use common semantics (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18870">18870</a>)
<li>Fix descriptor overload selection (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18868">18868</a>)
<li>Handle union types when binding <tt>self</tt> (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18867">18867</a>)
<li>Make variable override checking use common semantics (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18847">18847</a>)
<li>Make descriptor handling behave consistently (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18831">18831</a>)
</ul>
<h2>Make Implementation for Abstract Overloads Optional</h2>
<p>The implementation can now be omitted for abstract overloaded methods,
even outside stubs:
<pre><code class="language-py">from abc import abstractmethod
from typing import overload
class C:
@abstractmethod
@overload
def foo(self, x: int) -> int: ...
@abstractmethod
@overload
def foo(self, x: str) -> str: ...
# No implementation required for "foo"
</code></pre>
<p>This was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/18882">18882</a>).
<h2>Option to Exclude Everything in .gitignore</h2>
<p>You can now use <tt>--exclude-gitignore</tt> to exclude everything in a
<tt>.gitignore</tt> file from the mypy build. This behaves similar to
excluding the paths using <tt>--exclude</tt>. We might enable this by default
in a future mypy release.
<p>This was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/18696">18696</a>).
<h2>Selectively Disable Deprecated Warnings</h2>
<p>It's now possible to selectively disable warnings generated from
<a href="https://docs.python.org/3/library/warnings.html#warnings.deprecated"><tt>warnings.deprecated</tt></a>
using the <a href="https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-deprecated-calls-exclude"><tt>--deprecated-calls-exclude</tt></a>
option:
<pre><code class="language-python"># mypy --enable-error-code deprecated
# --deprecated-calls-exclude=foo.A
import foo
foo.A().func() # OK, the deprecated warning is ignored
</code></pre>
<pre><code class="language-python"># file foo.py
from typing_extensions import deprecated
class A:
@deprecated("Use A.func2 instead")
def func(self): pass
...
</code></pre>
<p>Contributed by Marc Mueller (PR <a href="https://github.com/python/mypy/pull/18641">18641</a>)
<h2>Annotating Native/Non-Native Classes in Mypyc</h2>
<p>You can now declare a class as a non-native class when compiling with
mypyc. Unlike native classes, which are extension classes and have an
immutable structure, non-native classes are normal Python classes at
runtime and are fully dynamic. Example:
<pre><code class="language-python">from mypy_extensions import mypyc_attr
@mypyc_attr(native_class=False)
class NonNativeClass:
...
o = NonNativeClass()
# Ok, even if attribute "foo" not declared in class body
setattr(o, "foo", 1)
</code></pre>
<p>Classes are native by default in compiled modules, but classes that
use certain features (such as most metaclasses) are implicitly
non-native.
<p>You can also explicitly declare a class as native. In this case mypyc
will generate an error if it can't compile the class as a native
class, instead of falling back to a non-native class:
<pre><code class="language-python">from mypy_extensions import mypyc_attr
from foo import MyMeta
# Error: Unsupported metaclass for a native class
@mypyc_attr(native_class=True)
class C(metaclass=MyMeta):
...
</code></pre>
<p>Since native classes are significantly more efficient that non-native
classes, you may want to ensure that certain classes always compiled
as native classes.
<p>This feature was contributed by Valentin Stanciu (PR <a href="https://github.com/python/mypy/pull/18802">18802</a>).
<h2>Mypyc Fixes and Improvements</h2>
<p><ul>
<li>Improve documentation of native and non-native classes (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/19154">19154</a>)
<li>Fix compilation when using Python 3.13 debug build (Valentin Stanciu, PR <a href="https://github.com/python/mypy/pull/19045">19045</a>)
<li>Show the reason why a class can't be a native class (Valentin Stanciu, PR <a href="https://github.com/python/mypy/pull/19016">19016</a>)
<li>Support await/yield while temporary values are live (Michael J. Sullivan, PR <a href="https://github.com/python/mypy/pull/16305">16305</a>)
<li>Fix spilling values with overlapping error values (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/18961">18961</a>)
<li>Fix reference count of spilled register in async def (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/18957">18957</a>)
<li>Add basic optimization for <tt>sorted</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18902">18902</a>)
<li>Fix access of class object in a type annotation (Advait Dixit, PR <a href="https://github.com/python/mypy/pull/18874">18874</a>)
<li>Optimize <tt>list.__imul__</tt> and <tt>tuple.__mul__ </tt>(Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18887">18887</a>)
<li>Optimize <tt>list.__add__</tt>, <tt>list.__iadd__</tt> and <tt>tuple.__add__</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18845">18845</a>)
<li>Add and implement primitive <tt>list.copy()</tt> (exertustfm, PR <a href="https://github.com/python/mypy/pull/18771">18771</a>)
<li>Optimize <tt>builtins.repr</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18844">18844</a>)
<li>Support iterating over keys/values/items of dict-bound TypeVar and ParamSpec.kwargs (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18789">18789</a>)
<li>Add efficient primitives for <tt>str.strip()</tt> etc. (Advait Dixit, PR <a href="https://github.com/python/mypy/pull/18742">18742</a>)
<li>Document that <tt>strip()</tt> etc. are optimized (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/18793">18793</a>)
<li>Fix mypyc crash with enum type aliases (Valentin Stanciu, PR <a href="https://github.com/python/mypy/pull/18725">18725</a>)
<li>Optimize <tt>str.find</tt> and <tt>str.rfind</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18709">18709</a>)
<li>Optimize <tt>str.__contains__</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18705">18705</a>)
<li>Fix order of steal/unborrow in tuple unpacking (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18732">18732</a>)
<li>Optimize <tt>str.partition</tt> and <tt>str.rpartition</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18702">18702</a>)
<li>Optimize <tt>str.startswith</tt> and <tt>str.endswith</tt> with tuple argument (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18678">18678</a>)
<li>Improve <tt>str.startswith</tt> and <tt>str.endswith</tt> with tuple argument (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18703">18703</a>)
<li><tt>pythoncapi_compat</tt>: don't define Py_NULL if it is already defined (Michael R. Crusoe, PR <a href="https://github.com/python/mypy/pull/18699">18699</a>)
<li>Optimize <tt>str.splitlines</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18677">18677</a>)
<li>Mark <tt>dict.setdefault</tt> as optimized (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18685">18685</a>)
<li>Support <tt>__del__</tt> methods (Advait Dixit, PR <a href="https://github.com/python/mypy/pull/18519">18519</a>)
<li>Optimize <tt>str.rsplit</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18673">18673</a>)
<li>Optimize <tt>str.removeprefix</tt> and <tt>str.removesuffix</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18672">18672</a>)
<li>Recognize literal types in <tt>__match_args__</tt> (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18636">18636</a>)
<li>Fix non extension classes with attribute annotations using forward references (Valentin Stanciu, PR <a href="https://github.com/python/mypy/pull/18577">18577</a>)
<li>Use lower-case generic types such as <tt>list[t]</tt> in documentation (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/18576">18576</a>)
<li>Improve support for <tt>frozenset</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18571">18571</a>)
<li>Fix wheel build for cp313-win (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18560">18560</a>)
<li>Reduce impact of immortality (introduced in Python 3.12) on reference counting performance (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/18459">18459</a>)
<li>Update math error messages for 3.14 (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18534">18534</a>)
<li>Update math error messages for 3.14 (2) (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18949">18949</a>)
<li>Replace deprecated <tt>_PyLong_new</tt> with <tt>PyLongWriter</tt> API (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18532">18532</a>)
</ul>
<h2>Fixes to Crashes</h2>
<p><ul>
<li>Traverse module ancestors when traversing reachable graph nodes during dmypy update (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18906">18906</a>)
<li>Fix crash on multiple unpacks in a bare type application (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18857">18857</a>)
<li>Prevent crash when enum/TypedDict call is stored as a class attribute (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18861">18861</a>)
<li>Fix crash on multiple unpacks in a bare type application (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18857">18857</a>)
<li>Fix crash on type inference against non-normal callables (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18858">18858</a>)
<li>Fix crash on decorated getter in settable property (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18787">18787</a>)
<li>Fix crash on callable with <tt>*args</tt> and suffix against Any (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18781">18781</a>)
<li>Fix crash on deferred supertype and setter override (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18649">18649</a>)
<li>Fix crashes on incorrectly detected recursive aliases (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18625">18625</a>)
<li>Report that <tt>NamedTuple</tt> and <tt>dataclass</tt> are incompatile instead of crashing (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/18633">18633</a>)
<li>Fix mypy daemon crash (Valentin Stanciu, PR <a href="https://github.com/python/mypy/pull/19087">19087</a>)
</ul>
<h2>Performance Improvements</h2>
<p>These are specific to mypy. Mypyc-related performance improvements are discussed elsewhere.
<p><ul>
<li>Speed up binding <tt>self</tt> in trivial cases (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19024">19024</a>)
<li>Small constraint solver optimization (Aaron Gokaslan, PR <a href="https://github.com/python/mypy/pull/18688">18688</a>)
</ul>
<h2>Documentation Updates</h2>
<p><ul>
<li>Improve documentation of <tt>--strict</tt> (lenayoung8, PR <a href="https://github.com/python/mypy/pull/18903">18903</a>)
<li>Remove a note about <tt>from __future__ import annotations</tt> (Ageev Maxim, PR <a href="https://github.com/python/mypy/pull/18915">18915</a>)
<li>Improve documentation on type narrowing (Tim Hoffmann, PR <a href="https://github.com/python/mypy/pull/18767">18767</a>)
<li>Fix metaclass usage example (Georg, PR <a href="https://github.com/python/mypy/pull/18686">18686</a>)
<li>Update documentation on <tt>extra_checks</tt> flag (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18537">18537</a>)
</ul>
<h2>Stubgen Improvements</h2>
<p><ul>
<li>Fix <tt>TypeAlias</tt> handling (Alexey Makridenko, PR <a href="https://github.com/python/mypy/pull/18960">18960</a>)
<li>Handle <tt>arg=None</tt> in C extension modules (Anthony Sottile, PR <a href="https://github.com/python/mypy/pull/18768">18768</a>)
<li>Fix valid type detection to allow pipe unions (Chad Dombrova, PR <a href="https://github.com/python/mypy/pull/18726">18726</a>)
<li>Include simple decorators in stub files (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18489">18489</a>)
<li>Support positional and keyword-only arguments in stubdoc (Paul Ganssle, PR <a href="https://github.com/python/mypy/pull/18762">18762</a>)
<li>Fall back to <tt>Incomplete</tt> if we are unable to determine the module name (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19084">19084</a>)
</ul>
<h2>Stubtest Improvements</h2>
<p><ul>
<li>Make stubtest ignore <tt>__slotnames__</tt> (Nick Pope, PR <a href="https://github.com/python/mypy/pull/19077">19077</a>)
<li>Fix stubtest tests on 3.14 (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/19074">19074</a>)
<li>Support for <tt>strict_bytes</tt> in stubtest (Joren Hammudoglu, PR <a href="https://github.com/python/mypy/pull/19002">19002</a>)
<li>Understand override (Shantanu, PR <a href="https://github.com/python/mypy/pull/18815">18815</a>)
<li>Better checking of runtime arguments with dunder names (Shantanu, PR <a href="https://github.com/python/mypy/pull/18756">18756</a>)
<li>Ignore setattr and delattr inherited from object (Stephen Morton, PR <a href="https://github.com/python/mypy/pull/18325">18325</a>)
</ul>
<h2>Miscellaneous Fixes and Improvements</h2>
<p><ul>
<li>Add <tt>--strict-bytes</tt> to <tt>--strict</tt> (wyattscarpenter, PR <a href="https://github.com/python/mypy/pull/19049">19049</a>)
<li>Admit that Final variables are never redefined (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19083">19083</a>)
<li>Add special support for <tt>@django.cached_property</tt> needed in <tt>django-stubs</tt> (sobolevn, PR <a href="https://github.com/python/mypy/pull/18959">18959</a>)
<li>Do not narrow types to <tt>Never</tt> with binder (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18972">18972</a>)
<li>Local forward references should precede global forward references (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/19000">19000</a>)
<li>Do not cache module lookup results in incremental mode that may become invalid (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19044">19044</a>)
<li>Only consider meta variables in ambiguous "any of" constraints (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18986">18986</a>)
<li>Allow accessing <tt>__init__</tt> on final classes and when <tt>__init__</tt> is final (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/19035">19035</a>)
<li>Treat varargs as positional-only (A5rocks, PR <a href="https://github.com/python/mypy/pull/19022">19022</a>)
<li>Enable colored output for argparse help in Python 3.14 (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/19021">19021</a>)
<li>Fix argparse for Python 3.14 (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/19020">19020</a>)
<li><tt>dmypy suggest</tt> can now suggest through contextmanager-based decorators (Anthony Sottile, PR <a href="https://github.com/python/mypy/pull/18948">18948</a>)
<li>Fix <tt>__r<magic_methods>__</tt> being used under the same <tt>__<magic_method>__</tt> hook (Arnav Jain, PR <a href="https://github.com/python/mypy/pull/18995">18995</a>)
<li>Prioritize <tt>.pyi</tt> from <tt>-stubs</tt> packages over bundled <tt>.pyi</tt> (Joren Hammudoglu, PR <a href="https://github.com/python/mypy/pull/19001">19001</a>)
<li>Fix missing subtype check case for <tt>type[T]</tt> (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18975">18975</a>)
<li>Fixes to the detection of redundant casts (Anthony Sottile, PR <a href="https://github.com/python/mypy/pull/18588">18588</a>)
<li>Make some parse errors non-blocking (Shantanu, PR <a href="https://github.com/python/mypy/pull/18941">18941</a>)
<li>Fix PEP 695 type alias with a mix of type arguments (PEP 696) (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18919">18919</a>)
<li>Allow deeper recursion in mypy daemon, better error reporting (Carter Dodd, PR <a href="https://github.com/python/mypy/pull/17707">17707</a>)
<li>Fix swapped errors for frozen/non-frozen dataclass inheritance (Nazrawi Demeke, PR <a href="https://github.com/python/mypy/pull/18918">18918</a>)
<li>Fix incremental issue with namespace packages (Shantanu, PR <a href="https://github.com/python/mypy/pull/18907">18907</a>)
<li>Exclude irrelevant members when narrowing union overlapping with enum (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18897">18897</a>)
<li>Flatten union before contracting literals when checking subtyping (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18898">18898</a>)
<li>Do not add <tt>kw_only</tt> dataclass fields to <tt>__match_args__</tt> (sobolevn, PR <a href="https://github.com/python/mypy/pull/18892">18892</a>)
<li>Fix error message when returning long tuple with type mismatch (Thomas Mattone, PR <a href="https://github.com/python/mypy/pull/18881">18881</a>)
<li>Treat <tt>TypedDict</tt> (old-style) aliases as regular <tt>TypedDict</tt>s (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18852">18852</a>)
<li>Warn about unused <tt>type: ignore</tt> comments when error code is disabled (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18849">18849</a>)
<li>Reject duplicate <tt>ParamSpec.{args,kwargs}</tt> at call site (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18854">18854</a>)
<li>Make detection of enum members more consistent (sobolevn, PR <a href="https://github.com/python/mypy/pull/18675">18675</a>)
<li>Admit that <tt>**kwargs</tt> mapping subtypes may have no direct type parameters (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18850">18850</a>)
<li>Don't suggest <tt>types-setuptools</tt> for <tt>pkg_resources</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/18840">18840</a>)
<li>Suggest <tt>scipy-stubs</tt> for <tt>scipy</tt> as non-typeshed stub package (Joren Hammudoglu, PR <a href="https://github.com/python/mypy/pull/18832">18832</a>)
<li>Narrow tagged unions in match statements (Gene Parmesan Thomas, PR <a href="https://github.com/python/mypy/pull/18791">18791</a>)
<li>Consistently store settable property type (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18774">18774</a>)
<li>Do not blindly undefer on leaving function (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18674">18674</a>)
<li>Process superclass methods before subclass methods in semanal (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18723">18723</a>)
<li>Only defer top-level functions (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18718">18718</a>)
<li>Add one more type-checking pass (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18717">18717</a>)
<li>Properly account for <tt>member</tt> and <tt>nonmember</tt> in enums (sobolevn, PR <a href="https://github.com/python/mypy/pull/18559">18559</a>)
<li>Fix instance vs tuple subtyping edge case (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18664">18664</a>)
<li>Improve handling of Any/object in variadic generics (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18643">18643</a>)
<li>Fix handling of named tuples in class match pattern (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18663">18663</a>)
<li>Fix regression for user config files (Shantanu, PR <a href="https://github.com/python/mypy/pull/18656">18656</a>)
<li>Fix dmypy socket issue on GNU/Hurd (Mattias Ellert, PR <a href="https://github.com/python/mypy/pull/18630">18630</a>)
<li>Don't assume that for loop body index variable is always set (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/18631">18631</a>)
<li>Fix overlap check for variadic generics (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18638">18638</a>)
<li>Improve support for <tt>functools.partial</tt> of overloaded callable protocol (Shantanu, PR <a href="https://github.com/python/mypy/pull/18639">18639</a>)
<li>Allow lambdas in <tt>except*</tt> clauses (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18620">18620</a>)
<li>Fix trailing commas in many multiline string options in <tt>pyproject.toml</tt> (sobolevn, PR <a href="https://github.com/python/mypy/pull/18624">18624</a>)
<li>Allow trailing commas for <tt>files</tt> setting in <tt>mypy.ini</tt> and <tt>setup.ini</tt> (sobolevn, PR <a href="https://github.com/python/mypy/pull/18621">18621</a>)
<li>Fix "not callable" issue for <tt>@dataclass(frozen=True)</tt> with <tt>Final</tt> attr (sobolevn, PR <a href="https://github.com/python/mypy/pull/18572">18572</a>)
<li>Add missing TypedDict special case when checking member access (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18604">18604</a>)
<li>Use lower case <tt>list</tt> and <tt>dict</tt> in invariance notes (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/18594">18594</a>)
<li>Fix inference when class and instance match protocol (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18587">18587</a>)
<li>Remove support for <tt>builtins.Any</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18578">18578</a>)
<li>Update the overlapping check for tuples to account for NamedTuples (A5rocks, PR <a href="https://github.com/python/mypy/pull/18564">18564</a>)
<li>Fix <tt>@deprecated</tt> (PEP 702) with normal overloaded methods (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/18477">18477</a>)
<li>Start propagating end columns/lines for <tt>type-arg</tt> errors (A5rocks, PR <a href="https://github.com/python/mypy/pull/18533">18533</a>)
<li>Improve handling of <tt>type(x) is Foo</tt> checks (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18486">18486</a>)
<li>Suggest <tt>typing.Literal</tt> for exit-return error messages (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18541">18541</a>)
<li>Allow redefinitions in except/else/finally (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18515">18515</a>)
<li>Disallow setting Python version using inline config (Shantanu, PR <a href="https://github.com/python/mypy/pull/18497">18497</a>)
<li>Improve type inference in tuple multiplication plugin (Shantanu, PR <a href="https://github.com/python/mypy/pull/18521">18521</a>)
<li>Add missing line number to <tt>yield from</tt> with wrong type (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18518">18518</a>)
<li>Hint at argument names when formatting callables with compatible return types in error messages (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18495">18495</a>)
<li>Add better naming and improve compatibility for ad hoc intersections of instances (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/18506">18506</a>)
</ul>
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<p><ul>
<li>A5rocks
<li>Aaron Gokaslan
<li>Advait Dixit
<li>Ageev Maxim
<li>Alexey Makridenko
<li>Ali Hamdan
<li>Anthony Sottile
<li>Arnav Jain
<li>Brian Schubert
<li>bzoracler
<li>Carter Dodd
<li>Chad Dombrova
<li>Christoph Tyralla
<li>Dimitri Papadopoulos Orfanos
<li>Emma Smith
<li>exertustfm
<li>Gene Parmesan Thomas
<li>Georg
<li>Ivan Levkivskyi
<li>Jared Hance
<li>Jelle Zijlstra
<li>Joren Hammudoglu
<li>lenayoung8
<li>Marc Mueller
<li>Mattias Ellert
<li>Michael J. Sullivan
<li>Michael R. Crusoe
<li>Nazrawi Demeke
<li>Nick Pope
<li>Paul Ganssle
<li>Shantanu
<li>sobolevn
<li>Stanislav Terliakov
<li>Stephen Morton
<li>Thomas Mattone
<li>Tim Hoffmann
<li>Tim Ruffing
<li>Valentin Stanciu
<li>Wesley Collin Wright
<li>wyattscarpenter
</ul>
<p>I’d also like to thank my employer, Dropbox, for supporting mypy development.
</body>
</html>Jukka Lehtosalohttp://www.blogger.com/profile/00122775610277203624noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-25809666000136639212025-02-04T20:26:00.000-08:002025-02-04T20:35:28.835-08:00Mypy 1.15 Released<html>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/a11y-light.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script>hljs.configure({languages:["python","bash"]});hljs.highlightAll();</script>
<body>
<h1>Mypy 1.15 Released</h1>
<p>We’ve just uploaded mypy 1.15 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>).
Mypy is a static type checker for Python. This release includes new features, performance
improvements and bug fixes. You can install it as follows:
<pre><code>python3 -m pip install -U mypy
</code></pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Performance Improvements</h2>
<p>Mypy is up to 40% faster in some use cases. This improvement comes largely from tuning the performance
of the garbage collector. Additionally, the release includes several micro-optimizations that may
be impactful for large projects.
<p>Contributed by Jukka Lehtosalo (PR <a href="https://github.com/python/mypy/pull/18306">18306</a>,
PR <a href="https://github.com/python/mypy/pull/18302">18302</a>, PR <a href="https://github.com/python/mypy/pull/18298">18298</a>,
PR <a href="https://github.com/python/mypy/pull/18299">18299</a>).
<h2>Mypyc Accelerated Mypy Wheels for ARM Linux</h2>
<p>For best performance, mypy can be compiled to C extension modules using mypyc. This makes
mypy 3-5x faster than when interpreted with pure Python. We now build and upload mypyc
accelerated mypy wheels for <tt>manylinux_aarch64</tt> to PyPI, making it easy for Linux users on
ARM platforms to realise this speedup -- just <tt>pip install</tt> the latest mypy.
<p>Contributed by Christian Bundy and Marc Mueller
(PR <a href="https://github.com/mypyc/mypy_mypyc-wheels/pull/76">mypy_mypyc-wheels#76</a>,
PR <a href="https://github.com/mypyc/mypy_mypyc-wheels/pull/89">mypy_mypyc-wheels#89</a>).
<h2><tt>--strict-bytes</tt></h2>
<p>By default, mypy treats <tt>bytearray</tt> and <tt>memoryview</tt> values as assignable to the <tt>bytes</tt>
type, for historical reasons. Use the <tt>--strict-bytes</tt> flag to disable this
behavior. <a href="https://peps.python.org/pep-0688">PEP 688</a> specified the removal of this
special case. The flag will be enabled by default in <b>mypy 2.0</b>.
<p>Contributed by Ali Hamdan (PR <a href="https://github.com/python/mypy/pull/18263">18263</a>) and
Shantanu Jain (PR <a href="https://github.com/python/mypy/pull/13952">13952</a>).
<h2>Improvements to Reachability Analysis and Partial Type Handling in Loops</h2>
<p>This change results in mypy better modelling control flow within loops and hence detecting
several previously ignored issues. In some cases, this change may require additional
explicit variable annotations.
<p>Contributed by Christoph Tyralla (PR <a href="https://github.com/python/mypy/pull/18180">18180</a>,
PR <a href="https://github.com/python/mypy/pull/18433">18433</a>).
(Speaking of partial types, remember that we plan to enable <tt>--local-partial-types</tt>
by default in <b>mypy 2.0</b>.)
<h2>Better Discovery of Configuration Files</h2>
<p>Mypy will now walk up the filesystem (up until a repository or file system root) to discover
configuration files. See the
<a href="https://mypy.readthedocs.io/en/stable/config_file.html">mypy configuration file documentation</a>
for more details.
<p>Contributed by Mikhail Shiryaev and Shantanu Jain
(PR <a href="https://github.com/python/mypy/pull/16965">16965</a>, PR <a href="https://github.com/python/mypy/pull/18482">18482</a>)
<h2>Better Line Numbers for Decorators and Slice Expressions</h2>
<p>Mypy now uses more correct line numbers for decorators and slice expressions. In some cases,
you may have to change the location of a <tt># type: ignore</tt> comment.
<p>Contributed by Shantanu Jain (PR <a href="https://github.com/python/mypy/pull/18392">18392</a>,
PR <a href="https://github.com/python/mypy/pull/18397">18397</a>).
<h2>Drop Support for Python 3.8</h2>
<p>Mypy no longer supports running with Python 3.8, which has reached end-of-life.
When running mypy with Python 3.9+, it is still possible to type check code
that needs to support Python 3.8 with the <tt>--python-version 3.8</tt> argument.
Support for this will be dropped in the first half of 2025!
<p>Contributed by Marc Mueller (PR <a href="https://github.com/python/mypy/pull/17492">17492</a>).
<h2>Mypyc Improvements</h2>
<p><ul>
<li>Fix <tt>__init__</tt> for classes with <tt>@attr.s(slots=True)</tt> (Advait Dixit, PR <a href="https://github.com/python/mypy/pull/18447">18447</a>)
<li>Report error for nested class instead of crashing (Valentin Stanciu, PR <a href="https://github.com/python/mypy/pull/18460">18460</a>)
<li>Fix <tt>InitVar</tt> for dataclasses (Advait Dixit, PR <a href="https://github.com/python/mypy/pull/18319">18319</a>)
<li>Remove unnecessary mypyc files from wheels (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18416">18416</a>)
<li>Fix issues with relative imports (Advait Dixit, PR <a href="https://github.com/python/mypy/pull/18286">18286</a>)
<li>Add faster primitive for some list get item operations (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/18136">18136</a>)
<li>Fix iteration over <tt>NamedTuple</tt> objects (Advait Dixit, PR <a href="https://github.com/python/mypy/pull/18254">18254</a>)
<li>Mark mypyc package with <tt>py.typed</tt> (bzoracler, PR <a href="https://github.com/python/mypy/pull/18253">18253</a>)
<li>Fix list index while checking for <tt>Enum</tt> class (Advait Dixit, PR <a href="https://github.com/python/mypy/pull/18426">18426</a>)
</ul>
<h2>Stubgen Improvements</h2>
<p><ul>
<li>Improve dataclass init signatures (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18430">18430</a>)
<li>Preserve <tt>dataclass_transform</tt> decorator (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18418">18418</a>)
<li>Fix <tt>UnpackType</tt> for 3.11+ (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18421">18421</a>)
<li>Improve <tt>self</tt> annotations (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18420">18420</a>)
<li>Print <tt>InspectError</tt> traceback in stubgen <tt>walk_packages</tt> when verbose is specified (Gareth, PR <a href="https://github.com/python/mypy/pull/18224">18224</a>)
</ul>
<h2>Stubtest Improvements</h2>
<p><ul>
<li>Fix crash with numpy array default values (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/18353">18353</a>)
<li>Distinguish metaclass attributes from class attributes (Stephen Morton, PR <a href="https://github.com/python/mypy/pull/18314">18314</a>)
</ul>
<h2>Fixes to Crashes</h2>
<p><ul>
<li>Prevent crash with <tt>Unpack</tt> of a fixed tuple in PEP695 type alias (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18451">18451</a>)
<li>Fix crash with <tt>--cache-fine-grained --cache-dir=/dev/null</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/18457">18457</a>)
<li>Prevent crashing when <tt>match</tt> arms use name of existing callable (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18449">18449</a>)
<li>Gracefully handle encoding errors when writing to stdout (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18292">18292</a>)
<li>Prevent crash on generic NamedTuple with unresolved typevar bound (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18585">18585</a>)
</ul>
<h2>Documentation Updates</h2>
<p><ul>
<li>Add inline tabs to documentation (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18262">18262</a>)
<li>Document any <tt>TYPE_CHECKING</tt> name works (Shantanu, PR <a href="https://github.com/python/mypy/pull/18443">18443</a>)
<li>Update documentation to not mention 3.8 where possible (sobolevn, PR <a href="https://github.com/python/mypy/pull/18455">18455</a>)
<li>Mention <tt>ignore_errors</tt> in exclude documentation (Shantanu, PR <a href="https://github.com/python/mypy/pull/18412">18412</a>)
<li>Add <tt>Self</tt> misuse to common issues (Shantanu, PR <a href="https://github.com/python/mypy/pull/18261">18261</a>)
</ul>
<h2>Other Notable Fixes and Improvements</h2>
<p><ul>
<li>Fix literal context for ternary expressions (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18545">18545</a>)
<li>Ignore <tt>dataclass.__replace__</tt> LSP violations (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18464">18464</a>)
<li>Bind <tt>self</tt> to the class being defined when checking multiple inheritance (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18465">18465</a>)
<li>Fix attribute type resolution with multiple inheritance (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18415">18415</a>)
<li>Improve security of our GitHub Actions (sobolevn, PR <a href="https://github.com/python/mypy/pull/18413">18413</a>)
<li>Unwrap <tt>type[Union[...]]</tt> when solving type variable constraints (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18266">18266</a>)
<li>Allow <tt>Any</tt> to match sequence patterns in match/case (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18448">18448</a>)
<li>Fix parent generics mapping when overriding generic attribute with property (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18441">18441</a>)
<li>Add dedicated error code for explicit <tt>Any</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/18398">18398</a>)
<li>Reject invalid <tt>ParamSpec</tt> locations (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18278">18278</a>)
<li>Stop suggesting stubs that have been removed from typeshed (Shantanu, PR <a href="https://github.com/python/mypy/pull/18373">18373</a>)
<li>Allow inverting <tt>--local-partial-types</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/18377">18377</a>)
<li>Allow to use <tt>Final</tt> and <tt>ClassVar</tt> after Python 3.13 (정승원, PR <a href="https://github.com/python/mypy/pull/18358">18358</a>)
<li>Update suggestions to include latest stubs in typeshed (Shantanu, PR <a href="https://github.com/python/mypy/pull/18366">18366</a>)
<li>Fix <tt>--install-types</tt> masking failure details (wyattscarpenter, PR <a href="https://github.com/python/mypy/pull/17485">17485</a>)
<li>Reject promotions when checking against protocols (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/18360">18360</a>)
<li>Don't erase type object arguments in diagnostics (Shantanu, PR <a href="https://github.com/python/mypy/pull/18352">18352</a>)
<li>Clarify status in <tt>dmypy status</tt> output (Kcornw, PR <a href="https://github.com/python/mypy/pull/18331">18331</a>)
<li>Disallow no-argument generic aliases when using PEP 613 explicit aliases (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18173">18173</a>)
<li>Suppress errors for unreachable branches in conditional expressions (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18295">18295</a>)
<li>Do not allow <tt>ClassVar</tt> and <tt>Final</tt> in <tt>TypedDict</tt> and <tt>NamedTuple</tt> (sobolevn, PR <a href="https://github.com/python/mypy/pull/18281">18281</a>)
<li>Report error if not enough or too many types provided to <tt>TypeAliasType</tt> (bzoracler, PR <a href="https://github.com/python/mypy/pull/18308">18308</a>)
<li>Use more precise context for <tt>TypedDict</tt> plugin errors (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18293">18293</a>)
<li>Use more precise context for invalid type argument errors (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18290">18290</a>)
<li>Do not allow <tt>type[]</tt> to contain <tt>Literal</tt> types (sobolevn, PR <a href="https://github.com/python/mypy/pull/18276">18276</a>)
<li>Allow bytearray/bytes comparisons with <tt>--strict-bytes</tt> (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/18255">18255</a>)
</ul>
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<p><ul>
<li>Advait Dixit
<li>Ali Hamdan
<li>Brian Schubert
<li>bzoracler
<li>Cameron Matsui
<li>Christoph Tyralla
<li>Gareth
<li>Ivan Levkivskyi
<li>Jukka Lehtosalo
<li>Kcornw
<li>Marc Mueller
<li>Mikhail f. Shiryaev
<li>Shantanu
<li>sobolevn
<li>Stanislav Terliakov
<li>Stephen Morton
<li>Valentin Stanciu
<li>Viktor Szépe
<li>wyattscarpenter
<li>정승원
</ul>
<p>I’d also like to thank my employer, Dropbox, for supporting mypy development.
</body>
</html>Unknownnoreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-46313501922420276132024-12-20T07:28:00.000-08:002024-12-20T07:42:40.076-08:00Mypy 1.14 Released<html>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/a11y-light.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script>hljs.configure({languages:["python","bash"]});hljs.highlightAll();</script>
<body>
<p>We’ve just uploaded mypy 1.14 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>).
<p>Mypy is a static type checker for Python. This release includes new features and bug fixes.
<p>You can install it as follows:
<pre><code>python3 -m pip install -U mypy
</code></pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Change to Enum Membership Semantics</h2>
<p>As per the updated <a href="https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members">typing specification for enums</a>,
enum members must be left unannotated.
<pre><code>class Pet(Enum):
CAT = 1 # Member attribute
DOG = 2 # Member attribute
# New error: Enum members must be left unannotated
WOLF: int = 3
species: str # Considered a non-member attribute
</code></pre>
<p>In particular, the specification change can result in issues in type stubs (<tt>.pyi</tt> files), since
historically it was common to leave the value absent:
<pre><code># In a type stub (.pyi file)
class Pet(Enum):
# Change in semantics: previously considered members,
# now non-member attributes
CAT: int
DOG: int
# Mypy will now issue a warning if it detects this
# situation in type stubs:
# > Detected enum "Pet" in a type stub with zero
# > members. There is a chance this is due to a recent
# > change in the semantics of enum membership. If so,
# > use <tt>member = value</tt> to mark an enum member,
# > instead of <tt>member: type</tt>
class Pet(Enum):
# As per the specification, you should now do one of
# the following:
DOG = 1 # Member attribute with value 1 and known type
WOLF = cast(int, ...) # Member attribute with unknown
# value but known type
LION = ... # Member attribute with unknown value and
# unknown type
</code></pre>
<p>Contributed by Terence Honles (PR <a href="https://github.com/python/mypy/pull/17207">17207</a>) and
<p>Shantanu Jain (PR <a href="https://github.com/python/mypy/pull/18068">18068</a>).
<h2>Support for @deprecated Decorator (PEP 702)</h2>
<p>Mypy can now issue errors or notes when code imports a deprecated feature
explicitly with a <tt>from mod import depr</tt> statement, or uses a deprecated feature
imported otherwise or defined locally. Features are considered deprecated when
decorated with <tt>warnings.deprecated</tt>, as specified in <a href="https://peps.python.org/pep-0702">PEP 702</a>.
<p>You can enable the error code via <tt>--enable-error-code=deprecated</tt> on the mypy
command line or <tt>enable_error_code = deprecated</tt> in the mypy config file.
<p>Use the command line flag <tt>--report-deprecated-as-note</tt> or config file option
<tt>report_deprecated_as_note=True</tt> to turn all such errors into notes.
<p>Deprecation errors will be enabled by default in a future mypy version.
<p>This feature was contributed by Christoph Tyralla.
<p>List of changes:
<p><ul>
<li>Add basic support for PEP 702 (<tt>@deprecated</tt>) (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/17476">17476</a>)
<li>Support descriptors with <tt>@deprecated</tt> (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/18090">18090</a>)
<li>Make "deprecated" note an error, disabled by default (Valentin Stanciu, PR <a href="https://github.com/python/mypy/pull/18192">18192</a>)
<li>Consider all possible type positions with <tt>@deprecated</tt> (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/17926">17926</a>)
<li>Improve the handling of explicit type annotations in assignment statements with <tt>@deprecated</tt> (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/17899">17899</a>)
</ul>
<h2>Optionally Analyzing Untyped Modules</h2>
<p>Mypy normally doesn't analyze imports from third-party modules (installed using pip, for example)
if there are no stubs or a py.typed marker file. To force mypy to analyze these imports, you
can now use the <tt>--follow-untyped-imports</tt> flag or set the <tt>follow_untyped_imports</tt>
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.
<p>This feature was contributed by Jannick Kremer.
<p>List of changes:
<p><ul>
<li>Implement flag to allow type checking of untyped modules (Jannick Kremer, PR <a href="https://github.com/python/mypy/pull/17712">17712</a>)
<li>Warn about <tt>--follow-untyped-imports</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/18249">18249</a>)
</ul>
<h2>Support New Style Type Variable Defaults (PEP 696)</h2>
<p>Mypy now supports type variable defaults using the new syntax described in PEP 696, which
was introduced in Python 3.13. Example:
<pre><code>@dataclass
class Box[T = int]: # Set default for "T"
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]
</code></pre>
<p>This feature was contributed by Marc Mueller (PR <a href="https://github.com/python/mypy/pull/17985">17985</a>).
<h2>Improved For Loop Index Variable Type Narrowing</h2>
<p>Mypy now preserves the literal type of for loop index variables, to support <tt>TypedDict</tt>
lookups. Example:
<pre><code>from typing import TypedDict
class X(TypedDict):
hourly: int
daily: int
def func(x: X) -> int:
s = 0
for var in ("hourly", "daily"):
# "Union[Literal['hourly']?, Literal['daily']?]"
reveal_type(var)
# x[var] no longer triggers a literal-required error
s += x[var]
return s
</code></pre>
<p>This was contributed by Marc Mueller (PR <a href="https://github.com/python/mypy/pull/18014">18014</a>).
<h2>Mypyc Improvements</h2>
<p><ul>
<li>Document optimized bytes operations and additional str operations (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/18242">18242</a>)
<li>Add primitives and specialization for <tt>ord()</tt> (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/18240">18240</a>)
<li>Optimize <tt>str.encode</tt> with specializations for common used encodings (Valentin Stanciu, PR <a href="https://github.com/python/mypy/pull/18232">18232</a>)
<li>Fix fall back to generic operation for staticmethod and classmethod (Advait Dixit, PR <a href="https://github.com/python/mypy/pull/18228">18228</a>)
<li>Support unicode surrogates in string literals (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/18209">18209</a>)
<li>Fix index variable in for loop with <tt>builtins.enumerate</tt> (Advait Dixit, PR <a href="https://github.com/python/mypy/pull/18202">18202</a>)
<li>Fix check for enum classes (Advait Dixit, PR <a href="https://github.com/python/mypy/pull/18178">18178</a>)
<li>Fix loading type from imported modules (Advait Dixit, PR <a href="https://github.com/python/mypy/pull/18158">18158</a>)
<li>Fix initializers of final attributes in class body (Jared Hance, PR <a href="https://github.com/python/mypy/pull/18031">18031</a>)
<li>Fix name generation for modules with similar full names (aatle, PR <a href="https://github.com/python/mypy/pull/18001">18001</a>)
<li>Fix relative imports in <tt>__init__.py</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/17979">17979</a>)
<li>Optimize dunder methods (jairov4, PR <a href="https://github.com/python/mypy/pull/17934">17934</a>)
<li>Replace deprecated <tt>_PyDict_GetItemStringWithError</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/17930">17930</a>)
<li>Fix wheel build for cp313-win (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/17941">17941</a>)
<li>Use public PyGen_GetCode instead of vendored implementation (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/17931">17931</a>)
<li>Optimize calls to final classes (jairov4, PR <a href="https://github.com/python/mypy/pull/17886">17886</a>)
<li>Support ellipsis (<tt>...</tt>) expressions in class bodies (Newbyte, PR <a href="https://github.com/python/mypy/pull/17923">17923</a>)
<li>Sync <tt>pythoncapi_compat.h</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/17929">17929</a>)
<li>Add <tt>runtests.py mypyc-fast</tt> for running fast mypyc tests (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17906">17906</a>)
</ul>
<h2>Stubgen Improvements</h2>
<p><ul>
<li>Do not include mypy generated symbols (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/18137">18137</a>)
<li>Fix <tt>FunctionContext.fullname</tt> for nested classes (Chad Dombrova, PR <a href="https://github.com/python/mypy/pull/17963">17963</a>)
<li>Add flagfile support (Ruslan Sayfutdinov, PR <a href="https://github.com/python/mypy/pull/18061">18061</a>)
<li>Add support for PEP 695 and PEP 696 syntax (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/18054">18054</a>)
</ul>
<h2>Stubtest Improvements</h2>
<p><ul>
<li>Allow the use of <tt>--show-traceback</tt> and <tt>--pdb</tt> with stubtest (Stephen Morton, PR <a href="https://github.com/python/mypy/pull/18037">18037</a>)
<li>Verify <tt>__all__</tt> exists in stub (Sebastian Rittau, PR <a href="https://github.com/python/mypy/pull/18005">18005</a>)
<li>Stop telling people to use double underscores (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/17897">17897</a>)
</ul>
<h2>Documentation Updates</h2>
<p><ul>
<li>Update config file documentation (sobolevn, PR <a href="https://github.com/python/mypy/pull/18103">18103</a>)
<li>Improve contributor documentation for Windows (ag-tafe, PR <a href="https://github.com/python/mypy/pull/18097">18097</a>)
<li>Correct note about <tt>--disallow-any-generics</tt> flag in documentation (Abel Sen, PR <a href="https://github.com/python/mypy/pull/18055">18055</a>)
<li>Further caution against <tt>--follow-imports=skip</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/18048">18048</a>)
<li>Fix the edit page buttton link in documentation (Kanishk Pachauri, PR <a href="https://github.com/python/mypy/pull/17933">17933</a>)
</ul>
<h2>Other Notables Fixes and Improvements</h2>
<p><ul>
<li>Show <tt>Protocol</tt> <tt>__call__</tt> for arguments with incompatible types (MechanicalConstruct, PR <a href="https://github.com/python/mypy/pull/18214">18214</a>)
<li>Make join and meet symmetric with <tt>strict_optional</tt> (MechanicalConstruct, PR <a href="https://github.com/python/mypy/pull/18227">18227</a>)
<li>Preserve block unreachablility when checking function definitions with constrained TypeVars (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18217">18217</a>)
<li>Do not include non-init fields in the synthesized <tt>__replace__</tt> method for dataclasses (Victorien, PR <a href="https://github.com/python/mypy/pull/18221">18221</a>)
<li>Disallow <tt>TypeVar</tt> constraints parameterized by type variables (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18186">18186</a>)
<li>Always complain about invalid varargs and varkwargs (Shantanu, PR <a href="https://github.com/python/mypy/pull/18207">18207</a>)
<li>Set default strict_optional state to True (Shantanu, PR <a href="https://github.com/python/mypy/pull/18198">18198</a>)
<li>Preserve type variable default None in type alias (Sukhorosov Aleksey, PR <a href="https://github.com/python/mypy/pull/18197">18197</a>)
<li>Add checks for invalid usage of continue/break/return in <tt>except*</tt> block (coldwolverine, PR <a href="https://github.com/python/mypy/pull/18132">18132</a>)
<li>Do not consider bare TypeVar not overlapping with None for reachability analysis (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18138">18138</a>)
<li>Special case <tt>types.DynamicClassAttribute</tt> as property-like (Stephen Morton, PR <a href="https://github.com/python/mypy/pull/18150">18150</a>)
<li>Disallow bare <tt>ParamSpec</tt> in type aliases (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18174">18174</a>)
<li>Move long_description metadata to pyproject.toml (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18172">18172</a>)
<li>Support <tt>==</tt>-based narrowing of Optional (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/18163">18163</a>)
<li>Allow TypedDict assignment of Required item to NotRequired ReadOnly item (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18164">18164</a>)
<li>Allow nesting of Annotated with TypedDict special forms inside TypedDicts (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18165">18165</a>)
<li>Infer generic type arguments for slice expressions (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18160">18160</a>)
<li>Fix checking of match sequence pattern against bounded type variables (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18091">18091</a>)
<li>Fix incorrect truthyness for Enum types and literals (David Salvisberg, PR <a href="https://github.com/python/mypy/pull/17337">17337</a>)
<li>Move static project metadata to pyproject.toml (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/18146">18146</a>)
<li>Fallback to stdlib json if integer exceeds 64-bit range (q0w, PR <a href="https://github.com/python/mypy/pull/18148">18148</a>)
<li>Fix 'or' pattern structural matching exhaustiveness (yihong, PR <a href="https://github.com/python/mypy/pull/18119">18119</a>)
<li>Fix type inference of positional parameter in class pattern involving builtin subtype (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18141">18141</a>)
<li>Fix <tt>[override]</tt> error with no line number when argument node has no line number (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18122">18122</a>)
<li>Fix some dmypy crashes (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18098">18098</a>)
<li>Fix subtyping between instance type and overloaded (Shantanu, PR <a href="https://github.com/python/mypy/pull/18102">18102</a>)
<li>Clean up new_semantic_analyzer config (Shantanu, PR <a href="https://github.com/python/mypy/pull/18071">18071</a>)
<li>Issue warning for enum with no members in stub (Shantanu, PR <a href="https://github.com/python/mypy/pull/18068">18068</a>)
<li>Fix enum attributes are not members (Terence Honles, PR <a href="https://github.com/python/mypy/pull/17207">17207</a>)
<li>Fix crash when checking slice expression with step 0 in tuple index (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18063">18063</a>)
<li>Allow union-with-callable attributes to be overridden by methods (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18018">18018</a>)
<li>Emit <tt>[mutable-override]</tt> for covariant override of attribute with method (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18058">18058</a>)
<li>Support ParamSpec mapping with <tt>functools.partial</tt> (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/17355">17355</a>)
<li>Fix approved stub ignore, remove normpath (Shantanu, PR <a href="https://github.com/python/mypy/pull/18045">18045</a>)
<li>Make <tt>disallow-any-unimported</tt> flag invertible (Séamus Ó Ceanainn, PR <a href="https://github.com/python/mypy/pull/18030">18030</a>)
<li>Filter to possible package paths before trying to resolve a module (falsedrow, PR <a href="https://github.com/python/mypy/pull/18038">18038</a>)
<li>Fix overlap check for ParamSpec types (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/18040">18040</a>)
<li>Do not prioritize ParamSpec signatures during overload resolution (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/18033">18033</a>)
<li>Fix ternary union for literals (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/18023">18023</a>)
<li>Fix compatibility checks for conditional function definitions using decorators (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/18020">18020</a>)
<li>TypeGuard should be bool not Any when matching TypeVar (Evgeniy Slobodkin, PR <a href="https://github.com/python/mypy/pull/17145">17145</a>)
<li>Fix convert-cache tool (Shantanu, PR <a href="https://github.com/python/mypy/pull/17974">17974</a>)
<li>Fix generator comprehension with mypyc (Shantanu, PR <a href="https://github.com/python/mypy/pull/17969">17969</a>)
<li>Fix crash issue when using shadowfile with pretty (Max Chang, PR <a href="https://github.com/python/mypy/pull/17894">17894</a>)
<li>Fix multiple nested classes with new generics syntax (Max Chang, PR <a href="https://github.com/python/mypy/pull/17820">17820</a>)
<li>Better error for <tt>mypy -p package</tt> without py.typed (Joe Gordon, PR <a href="https://github.com/python/mypy/pull/17908">17908</a>)
<li>Emit error for <tt>raise NotImplemented</tt> (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/17890">17890</a>)
<li>Add <tt>is_lvalue</tt> attribute to AttributeContext (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/17881">17881</a>)
</ul>
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<p><ul>
<li>aatle
<li>Abel Sen
<li>Advait Dixit
<li>ag-tafe
<li>Alex Waygood
<li>Ali Hamdan
<li>Brian Schubert
<li>Carlton Gibson
<li>Chad Dombrova
<li>Chelsea Durazo
<li>chiri
<li>Christoph Tyralla
<li>coldwolverine
<li>David Salvisberg
<li>Ekin Dursun
<li>Evgeniy Slobodkin
<li>falsedrow
<li>Gaurav Giri
<li>Ihor
<li>Ivan Levkivskyi
<li>jairov4
<li>Jannick Kremer
<li>Jared Hance
<li>Jelle Zijlstra
<li>jianghuyiyuan
<li>Joe Gordon
<li>John Doknjas
<li>Jukka Lehtosalo
<li>Kanishk Pachauri
<li>Marc Mueller
<li>Max Chang
<li>MechanicalConstruct
<li>Newbyte
<li>q0w
<li>Ruslan Sayfutdinov
<li>Sebastian Rittau
<li>Shantanu
<li>sobolevn
<li>Stanislav Terliakov
<li>Stephen Morton
<li>Sukhorosov Aleksey
<li>Séamus Ó Ceanainn
<li>Terence Honles
<li>Valentin Stanciu
<li>vasiliy
<li>Victorien
<li>yihong
</ul>
<p>I’d also like to thank my employer, Dropbox, for supporting mypy development.</body>
</html>Unknownnoreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-86723030370851299752024-10-28T02:56:00.000-07:002024-10-28T02:56:28.979-07:00Mypy 1.13 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 1.13 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>).
<p>Mypy is a static type checker for Python. You can install it as follows:
<pre>
python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<p>Note that unlike typical releases, Mypy 1.13 does not have any changes to type checking semantics
from 1.12.1.
<h2>Improved Performance</h2>
<p>Mypy 1.13 contains several performance improvements. Users can expect mypy to be 5-20% faster.
<p>In environments with long search paths (such as environments using many editable installs), mypy
can be significantly faster, e.g. 2.2x faster in the use case targeted by these improvements.
<p>Mypy 1.13 allows use of the <tt>orjson</tt> library for handling the cache instead of the stdlib <tt>json</tt>,
for improved performance. You can ensure the presence of <tt>orjson</tt> using the <tt>faster-cache</tt> extra:
<pre>
python3 -m pip install -U mypy[faster-cache]
</pre>
<p>Mypy may depend on <tt>orjson</tt> by default in the future.
<p>These improvements were contributed by Shantanu.
<p>List of changes:
<p><ul>
<li>Significantly speed up file handling error paths (Shantanu, PR <a href="https://github.com/python/mypy/pull/17920">17920</a>)
<li>Use fast path in modulefinder more often (Shantanu, PR <a href="https://github.com/python/mypy/pull/17950">17950</a>)
<li>Let mypyc optimise os.path.join (Shantanu, PR <a href="https://github.com/python/mypy/pull/17949">17949</a>)
<li>Make is_sub_path faster (Shantanu, PR <a href="https://github.com/python/mypy/pull/17962">17962</a>)
<li>Speed up stubs suggestions (Shantanu, PR <a href="https://github.com/python/mypy/pull/17965">17965</a>)
<li>Use sha1 for hashing (Shantanu, PR <a href="https://github.com/python/mypy/pull/17953">17953</a>)
<li>Use orjson instead of json, when available (Shantanu, PR <a href="https://github.com/python/mypy/pull/17955">17955</a>)
<li>Add faster-cache extra, test in CI (Shantanu, PR <a href="https://github.com/python/mypy/pull/17978">17978</a>)
</ul>
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<p><ul>
<li>Shantanu Jain
<li>Jukka Lehtosalo
</ul></body>
</html>Jukka Lehtosalohttp://www.blogger.com/profile/00122775610277203624noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-38368049507642205692024-10-14T04:53:00.000-07:002024-10-14T07:56:34.051-07:00Mypy 1.12 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 1.12 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type
checker for Python. This release includes new features, performance improvements and bug fixes.
<p>You can install it as follows:
<pre>
python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Support Python 3.12 Syntax for Generics (PEP 695)</h2>
<p>Support for the new type parameter syntax introduced in Python 3.12 is now enabled by default,
documented, and no longer experimental. It was available through a feature flag in
mypy 1.11 as an experimental feature.
<p>This example demonstrates the new syntax:
<pre>
# Generic function
def f[T](x: T) -> T: ...
reveal_type(f(1)) # Revealed type is 'int'
# Generic class
class C[T]:
def __init__(self, x: T) -> None:
self.x = x
c = C('a')
reveal_type(c.x) # Revealed type is 'str'
# Type alias
type A[T] = C[list[T]]
</pre>
<p>For more information, refer to the <a href="https://mypy.readthedocs.io/en/latest/generics.html">documentation</a>.
<p>These improvements are included:
<p><ul>
<li>Document Python 3.12 type parameter syntax (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17816">17816</a>)
<li>Further documentation updates (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17826">17826</a>)
<li>Allow Self return types with contravariance (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17786">17786</a>)
<li>Enable new type parameter syntax by default (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17798">17798</a>)
<li>Generate error if new-style type alias used as base class (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17789">17789</a>)
<li>Inherit variance if base class has explicit variance (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17787">17787</a>)
<li>Fix crash on invalid type var reference (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17788">17788</a>)
<li>Fix covariance of frozen dataclasses (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17783">17783</a>)
<li>Allow covariance with attribute that has "<tt>_</tt>" name prefix (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17782">17782</a>)
<li>Support <tt>Annotated[...]</tt> in new-style type aliases (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17777">17777</a>)
<li>Fix nested generic classes (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17776">17776</a>)
<li>Add detection and error reporting for the use of incorrect expressions within the scope of a type parameter and a type alias (Kirill Podoprigora, PR <a href="https://github.com/python/mypy/pull/17560">17560</a>)
</ul>
<h2>Basic Support for Python 3.13</h2>
<p>This release adds partial support for Python 3.13 features and compiled binaries for
Python 3.13. Mypyc now also supports Python 3.13.
<p>In particular, these features are supported:
<p><ul>
<li>Various new stdlib features and changes (through typeshed stub improvements)
<li><tt>typing.ReadOnly</tt> (see below for more)
<li><tt>typing.TypeIs</tt> (added in mypy 1.10, <a href="https://peps.python.org/pep-0742/">PEP 742</a>)
<li>Type parameter defaults when using the legacy syntax (<a href="https://peps.python.org/pep-0696/">PEP 696</a>)
</ul>
<p>These features are not supported yet:
<p><ul>
<li><tt>warnings.deprecated</tt> (<a href="https://peps.python.org/pep-0702/">PEP 702</a>)
<li>Type parameter defaults when using Python 3.12 type parameter syntax
</ul>
<h2>Mypyc Support for Python 3.13</h2>
<p>Mypyc now supports Python 3.13. This was contributed by Marc Mueller, with additional
fixes by Jukka Lehtosalo. Free threaded Python 3.13 builds are not supported yet.
<p>List of changes:
<p><ul>
<li>Add additional includes for Python 3.13 (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/17506">17506</a>)
<li>Add another include for Python 3.13 (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/17509">17509</a>)
<li>Fix ManagedDict functions for Python 3.13 (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/17507">17507</a>)
<li>Update mypyc test output for Python 3.13 (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/17508">17508</a>)
<li>Fix <tt>PyUnicode</tt> functions for Python 3.13 (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/17504">17504</a>)
<li>Fix <tt>_PyObject_LookupAttrId</tt> for Python 3.13 (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/17505">17505</a>)
<li>Fix <tt>_PyList_Extend</tt> for Python 3.13 (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/17503">17503</a>)
<li>Fix <tt>gen_is_coroutine</tt> for Python 3.13 (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/17501">17501</a>)
<li>Fix <tt>_PyObject_FastCall</tt> for Python 3.13 (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/17502">17502</a>)
<li>Avoid uses of <tt>_PyObject_CallMethodOneArg</tt> on 3.13 (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17526">17526</a>)
<li>Don't rely on <tt>_PyType_CalculateMetaclass</tt> on 3.13 (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17525">17525</a>)
<li>Don't use <tt>_PyUnicode_FastCopyCharacters</tt> on 3.13 (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17524">17524</a>)
<li>Don't use <tt>_PyUnicode_EQ</tt> on 3.13, as it's no longer exported (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17523">17523</a>)
</ul>
<h2>Inferring Unions for Conditional Expressions</h2>
<p>Mypy now always tries to infer a union type for a conditional expression if left and right
operand types are different. This results in more precise inferred types and lets mypy detect
more issues. Example:
<pre>
s = "foo" if cond() else 1
# Type of "s" is now "str | int" (it used to be "object")
</pre>
<p>Notably, if one of the operands has type <tt>Any</tt>, the type of a conditional expression is
now <tt><type> | Any</tt>. Previously the inferred type was just <tt>Any</tt>. The new type essentially
indicates that the value can be of type <tt><type></tt>, and potentially of some (unknown) type.
<p>Most operations performed on the result must also be valid for <tt><type></tt>.
<p>Example where this is relevant:
<pre>
from typing import Any
def func(a: Any, b: bool) -> None:
x = a if b else None
# Type of x is "Any | None"
print(x.y) # Error: None has no attribute "y"
</pre>
<p>This feature was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/17427">17427</a>).
<h2>ReadOnly Support for TypedDict (PEP 705)</h2>
<p>You can now use <tt>typing.ReadOnly</tt> to specity TypedDict items as
read-only (<a href="https://peps.python.org/pep-0705/">PEP 705</a>):
<pre>
from typing import TypedDict
# Or "from typing ..." on Python 3.13
from typing_extensions import ReadOnly
class TD(TypedDict):
a: int
b: ReadOnly[int]
d: TD = {"a": 1, "b": 2}
d["a"] = 3 # OK
d["b"] = 5 # Error: "b" is ReadOnly
</pre>
<p>This feature was contributed by Nikita Sobolev (PR <a href="https://github.com/python/mypy/pull/17644">17644</a>).
<h2>Python 3.8 End of Life Approaching</h2>
<p>We are planning to drop support for Python 3.8 in the next mypy feature release or the
one after that. Python 3.8 reaches end of life in October 2024.
<h2>Planned Changes to Defaults</h2>
<p>We are planning to enable <tt>--local-partial-types</tt> by default in mypy 2.0. This will
often require at least minor code changes. This option is implicitly enabled by mypy
daemon, so this makes the behavior of daemon and non-daemon modes consistent.
<p>We recommend that mypy users start using local partial types soon (or to explicitly disable
them) to prepare for the change.
<p>This can also be configured in a mypy configuration file:
<pre>
local_partial_types = True
</pre>
<p>For more information, refer to the
<a href="https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-local-partial-types">documentation</a>.
<h2>Documentation Updates</h2>
<p>Mypy documentation now uses modern syntax variants and imports in many examples. Some
examples no longer work on Python 3.8, which is the earliest Python version that mypy supports.
<p>Notably, <tt>Iterable</tt> and other protocols/ABCs are imported from <tt>collections.abc</tt> instead of
<tt>typing</tt>:
<pre>
from collections.abc import Iterable, Callable
</pre>
<p>Examples also avoid the upper-case aliases to built-in types: <tt>list[str]</tt> is used instead
of <tt>List[str]</tt>. The <tt>X | Y</tt> union type syntax introduced in Python 3.10 is also now prevalent.
<p>List of documentation updates:
<p>
<ul>
<li>Document <tt>--output=json</tt> CLI option (Edgar Ramírez Mondragón, PR <a href="https://github.com/python/mypy/pull/17611">17611</a>)
<li>Update various references to deprecated type aliases in docs (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17829">17829</a>)
<li>Make "X | Y" union syntax more prominent in documentation (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17835">17835</a>)
<li>Discuss upper bounds before self types in documentation (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17827">17827</a>)
<li>Make changelog visible in mypy documentation (quinn-sasha, PR <a href="https://github.com/python/mypy/pull/17742">17742</a>)
<li>List all incomplete features in <tt>--enable-incomplete-feature</tt> docs (sobolevn, PR <a href="https://github.com/python/mypy/pull/17633">17633</a>)
<li>Remove the explicit setting of a pygments theme (Pradyun Gedam, PR <a href="https://github.com/python/mypy/pull/17571">17571</a>)
<li>Document ReadOnly with TypedDict (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17905">17905</a>)
<li>Document TypeIs (Chelsea Durazo, PR <a href="https://github.com/python/mypy/pull/17821">17821</a>)
</ul>
<h2>Experimental Inline TypedDict Syntax</h2>
<p>Mypy now supports a non-standard, experimental syntax for defining anonymous TypedDicts.
<p>Example:
<pre>
def func(n: str, y: int) -> {"name": str, "year": int}:
return {"name": n, "year": y}
</pre>
<p>The feature is disabled by default. Use <tt>--enable-incomplete-feature=InlineTypedDict</tt> to
enable it. <i>We might remove this feature in a future release.</i>
<p>This feature was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/17457">17457</a>).
<h2>Stubgen Improvements</h2>
<p><ul>
<li>Fix crash on literal class-level keywords (sobolevn, PR <a href="https://github.com/python/mypy/pull/17663">17663</a>)
<li>Stubgen add <tt>--version</tt> (sobolevn, PR <a href="https://github.com/python/mypy/pull/17662">17662</a>)
<li>Fix <tt>stubgen --no-analysis/--parse-only</tt> docs (sobolevn, PR <a href="https://github.com/python/mypy/pull/17632">17632</a>)
<li>Include keyword only args when generating signatures in stubgenc (Eric Mark Martin, PR <a href="https://github.com/python/mypy/pull/17448">17448</a>)
<li>Add support for detecting <tt>Literal</tt> types when extracting types from docstrings (Michael Carlstrom, PR <a href="https://github.com/python/mypy/pull/17441">17441</a>)
<li>Use <tt>Generator</tt> type var defaults (Sebastian Rittau, PR <a href="https://github.com/python/mypy/pull/17670">17670</a>)
</ul>
<h2>Stubtest Improvements</h2>
<p><ul>
<li>Add support for <tt>cached_property</tt> (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/17626">17626</a>)
<li>Add <tt>enable_incomplete_feature</tt> validation to <tt>stubtest</tt> (sobolevn, PR <a href="https://github.com/python/mypy/pull/17635">17635</a>)
<li>Fix error code handling in <tt>stubtest</tt> with <tt>--mypy-config-file</tt> (sobolevn, PR <a href="https://github.com/python/mypy/pull/17629">17629</a>)
</ul>
<h2>Other Notables Fixes and Improvements</h2>
<p><ul>
<li>Report error if using unsupported type parameter defaults (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17876">17876</a>)
<li>Fix re-processing cross-reference in mypy daemon when node kind changes (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17883">17883</a>)
<li>Don't use equality to narrow when value is IntEnum/StrEnum (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17866">17866</a>)
<li>Don't consider None vs IntEnum comparison ambiguous (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17877">17877</a>)
<li>Fix narrowing of IntEnum and StrEnum types (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17874">17874</a>)
<li>Filter overload items based on self type during type inference (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17873">17873</a>)
<li>Enable negative narrowing of union TypeVar upper bounds (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/17850">17850</a>)
<li>Fix issue with member expression formatting (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/17848">17848</a>)
<li>Avoid type size explosion when expanding types (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17842">17842</a>)
<li>Fix negative narrowing of tuples in match statement (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/17817">17817</a>)
<li>Narrow falsey str/bytes/int to literal type (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/17818">17818</a>)
<li>Test against latest Python 3.13, make testing 3.14 easy (Shantanu, PR <a href="https://github.com/python/mypy/pull/17812">17812</a>)
<li>Reject ParamSpec-typed callables calls with insufficient arguments (Stanislav Terliakov, PR <a href="https://github.com/python/mypy/pull/17323">17323</a>)
<li>Fix crash when passing too many type arguments to generic base class accepting single ParamSpec (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/17770">17770</a>)
<li>Fix TypeVar upper bounds sometimes not being displayed in pretty callables (Brian Schubert, PR <a href="https://github.com/python/mypy/pull/17802">17802</a>)
<li>Added error code for overlapping function signatures (Katrina Connors, PR <a href="https://github.com/python/mypy/pull/17597">17597</a>)
<li>Check for <tt>truthy-bool</tt> in <tt>not ...</tt> unary expressions (sobolevn, PR <a href="https://github.com/python/mypy/pull/17773">17773</a>)
<li>Add missing lines-covered and lines-valid attributes (Soubhik Kumar Mitra, PR <a href="https://github.com/python/mypy/pull/17738">17738</a>)
<li>Fix another crash scenario with recursive tuple types (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17708">17708</a>)
<li>Resolve TypeVar upper bounds in <tt>functools.partial</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/17660">17660</a>)
<li>Always reset binder when checking deferred nodes (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17643">17643</a>)
<li>Fix crash on a callable attribute with single unpack (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17641">17641</a>)
<li>Fix mismatched signature between checker plugin API and implementation (bzoracler, PR <a href="https://github.com/python/mypy/pull/17343">17343</a>)
<li>Indexing a type also produces a GenericAlias (Shantanu, PR <a href="https://github.com/python/mypy/pull/17546">17546</a>)
<li>Fix crash on self-type in callable protocol (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17499">17499</a>)
<li>Fix crash on NamedTuple with method and error in function (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17498">17498</a>)
<li>Add <tt>__replace__</tt> for dataclasses in 3.13 (Max Muoto, PR <a href="https://github.com/python/mypy/pull/17469">17469</a>)
<li>Fix help message for <tt>--no-namespace-packages</tt> (Raphael Krupinski, PR <a href="https://github.com/python/mypy/pull/17472">17472</a>)
<li>Fix typechecking for async generators (Danny Yang, PR <a href="https://github.com/python/mypy/pull/17452">17452</a>)
<li>Fix strict optional handling in attrs plugin (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17451">17451</a>)
<li>Allow mixing ParamSpec and TypeVarTuple in Generic (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17450">17450</a>)
<li>Improvements to <tt>functools.partial</tt> of types (Shantanu, PR <a href="https://github.com/python/mypy/pull/17898">17898</a>)
<li>Make ReadOnly TypedDict items covariant (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17904">17904</a>)
<li>Fix union callees with <tt>functools.partial</tt> (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17903">17903</a>)
<li>Improve handling of generic functions with <tt>functools.partial</tt> (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17925">17925</a>)
</ul>
<h2>Typeshed Updates</h2>
<p>Please see <a href="https://github.com/python/typeshed/commits/main?after=91a58b07cdd807b1d965e04ba85af2adab8bf924+0&branch=main&path=stdlib">git log</a> for full list of standard library typeshed stub changes.
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<p><ul>
<li>Ali Hamdan
<li>Anders Kaseorg
<li>Bénédikt Tran
<li>Brian Schubert
<li>bzoracler
<li>Chelsea Durazo
<li>Danny Yang
<li>Edgar Ramírez Mondragón
<li>Eric Mark Martin
<li>InSync
<li>Ivan Levkivskyi
<li>Jordandev678
<li>Katrina Connors
<li>Kirill Podoprigora
<li>Marc Mueller
<li>Max Muoto
<li>Max Murin
<li>Michael Carlstrom
<li>Michael I Chen
<li>Pradyun Gedam
<li>quinn-sasha
<li>Raphael Krupinski
<li>Sebastian Rittau
<li>Shantanu
<li>sobolevn
<li>Soubhik Kumar Mitra
<li>Stanislav Terliakov
<li>wyattscarpenter
</ul>
<p>I’d also like to thank my employer, Dropbox, for supporting mypy development.</body>Jukka Lehtosalohttp://www.blogger.com/profile/00122775610277203624noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-26146098876381092632024-07-19T11:05:00.000-07:002024-08-29T02:57:11.450-07:00Mypy 1.11 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 1.11 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type checker for Python. This release includes new features, performance improvements and bug fixes. You can install it as follows:
<pre>
python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Support Python 3.12 Syntax for Generics (PEP 695)</h2>
<p>Mypy now supports the new type parameter syntax introduced in Python 3.12 (<a href="https://peps.python.org/pep-0695/">PEP 695</a>).
<p>This feature is still experimental and must be enabled with the <tt>--enable-incomplete-feature=NewGenericSyntax</tt> flag, or with <tt>enable_incomplete_feature = NewGenericSyntax</tt> in the mypy configuration file.
<p>We plan to enable this by default in the next mypy feature release.
<p>This example demonstrates the new syntax:
<pre>
# Generic function
def f<a href="x: T">T</a> -> T: ...
reveal_type(f(1)) # Revealed type is 'int'
# Generic class
class C[T]:
def __init__(self, x: T) -> None:
self.x = x
c = C('a')
reveal_type(c.x) # Revealed type is 'str'
# Type alias
type A[T] = C[list[T]]
</pre>
<p>This feature was contributed by Jukka Lehtosalo.
<h2>Support for <tt>functools.partial</tt></h2>
<p>Mypy now type checks uses of <tt>functools.partial</tt>. Previously mypy would accept arbitrary arguments.
<p>This example will now produce an error:
<pre>
from functools import partial
def f(a: int, b: str) -> None: ...
g = partial(f, 1)
# Argument has incompatible type "int"; expected "str"
g(11)
</pre>
<p>This feature was contributed by Shantanu (PR <a href="https://github.com/python/mypy/pull/16939">16939</a>).
<h2>Stricter Checks for Untyped Overrides</h2>
<p>Past mypy versions didn't check if untyped methods were compatible with overridden methods. This would result in false negatives. Now mypy performs these checks when using <tt>--check-untyped-defs</tt>.
<p>For example, this now generates an error if using <tt>--check-untyped-defs</tt>:
<pre>
class Base:
def f(self, x: int = 0) -> None: ...
class Derived(Base):
# Signature incompatible with "Base"
def f(self): ...
</pre>
<p>This feature was contributed by Steven Troxler (PR <a href="https://github.com/python/mypy/pull/17276">17276</a>).
<h2>Type Inference Improvements</h2>
<p>The new polymorphic inference algorithm introduced in mypy 1.5 is now used in more situations. This improves type inference involving generic higher-order functions, in particular.
<p>This feature was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/17348">17348</a>).
<p>Mypy now uses unions of tuple item types in certain contexts to enable more precise inferred types. Example:
<pre>
for x in (1, 'x'):
# Previously inferred as 'object'
reveal_type(x) # Revealed type is 'int | str'
</pre>
<p>This was also contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/17408">17408</a>).
<h2>Improvements to Detection of Overlapping Overloads</h2>
<p>The details of how mypy checks if two <tt>@overload</tt> signatures are unsafely overlapping were overhauled. This both fixes some false positives, and allows mypy to detect additional unsafe signatures.
<p>This feature was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/17392">17392</a>).
<h2>Better Support for Type Hints in Expressions</h2>
<p>Mypy now allows more expressions that evaluate to valid type annotations in all expression contexts. The inferred types of these expressions are also sometimes more precise. Previously they were often <tt>object</tt>.
<p>This example uses a union type that includes a callable type as an expression, and it no longer generates an error:
<pre>
from typing import Callable
print(Callable[[], int] | None) # No error
</pre>
<p>This feature was contributed by Jukka Lehtosalo (PR <a href="https://github.com/python/mypy/pull/17404">17404</a>).
<h2>Mypyc Improvements</h2>
<p>Mypyc now supports the new syntax for generics introduced in Python 3.12 (see above). Another notable improvement is signficantly faster basic operations on <tt>int</tt> values.
<p><ul>
<li>Support Python 3.12 syntax for generic functions and classes (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17357">17357</a>)
<li>Support Python 3.12 type alias syntax (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17384">17384</a>)
<li>Fix ParamSpec (Shantanu, PR <a href="https://github.com/python/mypy/pull/17309">17309</a>)
<li>Inline fast paths of integer unboxing operations (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17266">17266</a>)
<li>Inline tagged integer arithmetic and bitwise operations (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17265">17265</a>)
<li>Allow specifying primitives as pure (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17263">17263</a>)
</ul>
<h2>Changes to Stubtest</h2>
<p><ul>
<li>Ignore <tt>_ios_support</tt> (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/17270">17270</a>)
<li>Improve support for Python 3.13 (Shantanu, PR <a href="https://github.com/python/mypy/pull/17261">17261</a>)
</ul>
<h2>Changes to Stubgen</h2>
<p><ul>
<li>Gracefully handle invalid <tt>Optional</tt> and recognize aliases to PEP 604 unions (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/17386">17386</a>)
<li>Fix for Python 3.13 (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/17290">17290</a>)
<li>Preserve enum value initialisers (Shantanu, PR <a href="https://github.com/python/mypy/pull/17125">17125</a>)
</ul>
<h2>Miscellaneous New Features</h2>
<p><ul>
<li>Add error format support and JSON output option via <tt>--output json</tt> (Tushar Sadhwani, PR <a href="https://github.com/python/mypy/pull/11396">11396</a>)
<li>Support <tt>enum.member</tt> in Python 3.11+ (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/17382">17382</a>)
<li>Support <tt>enum.nonmember</tt> in Python 3.11+ (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/17376">17376</a>)
<li>Support <tt>namedtuple.__replace__</tt> in Python 3.13 (Shantanu, PR <a href="https://github.com/python/mypy/pull/17259">17259</a>)
<li>Support <tt>rename=True</tt> in collections.namedtuple (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/17247">17247</a>)
<li>Add support for <tt>__spec__</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/14739">14739</a>)
</ul>
<h2>Changes to Error Reporting</h2>
<p><ul>
<li>Mention <tt>--enable-incomplete-feature=NewGenericSyntax</tt> in messages (Shantanu, PR <a href="https://github.com/python/mypy/pull/17462">17462</a>)
<li>Do not report plugin-generated methods with <tt>explicit-override</tt> (sobolevn, PR <a href="https://github.com/python/mypy/pull/17433">17433</a>)
<li>Use and display namespaces for function type variables (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17311">17311</a>)
<li>Fix false positive for Final local scope variable in Protocol (GiorgosPapoutsakis, PR <a href="https://github.com/python/mypy/pull/17308">17308</a>)
<li>Use Never in more messages, use ambiguous in join (Shantanu, PR <a href="https://github.com/python/mypy/pull/17304">17304</a>)
<li>Log full path to config file in verbose output (dexterkennedy, PR <a href="https://github.com/python/mypy/pull/17180">17180</a>)
<li>Added <tt>[prop-decorator]</tt> code for unsupported property decorators (Christopher Barber, PR <a href="https://github.com/python/mypy/pull/16571, PR <a href="https://github.com/python/mypy/pull/14461">14461</a>">16571</a>)
<li>Suppress second error message with <tt>:=</tt> and <tt>[truthy-bool]</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/15941">15941</a>)
<li>Generate error for assignment of functional Enum to variable of different name (Shantanu, PR <a href="https://github.com/python/mypy/pull/16805">16805</a>)
<li>Fix error reporting on cached run after uninstallation of third party library (Shantanu, PR <a href="https://github.com/python/mypy/pull/17420">17420</a>)
</ul>
<h2>Fixes for Crashes</h2>
<p><ul>
<li>Fix daemon crash on invalid type in TypedDict (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17495">17495</a>)
<li>Fix crash and bugs related to <tt>partial()</tt> (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17423">17423</a>)
<li>Fix crash when overriding with unpacked TypedDict (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17359">17359</a>)
<li>Fix crash on TypedDict unpacking for ParamSpec (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17358">17358</a>)
<li>Fix crash involving recursive union of tuples (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17353">17353</a>)
<li>Fix crash on invalid callable property override (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17352">17352</a>)
<li>Fix crash on unpacking self in NamedTuple (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17351">17351</a>)
<li>Fix crash on recursive alias with an optional type (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17350">17350</a>)
<li>Fix crash on type comment inside generic definitions (Bénédikt Tran, PR <a href="https://github.com/python/mypy/pull/16849">16849</a>)
</ul>
<h2>Changes to Documentation</h2>
<p><ul>
<li>Use inline config in documentation for optional error codes (Shantanu, PR <a href="https://github.com/python/mypy/pull/17374">17374</a>)
<li>Use lower-case generics in documentation (Seo Sanghyeon, PR <a href="https://github.com/python/mypy/pull/17176">17176</a>)
<li>Add documentation for show-error-code-links (GiorgosPapoutsakis, PR <a href="https://github.com/python/mypy/pull/17144">17144</a>)
<li>Update CONTRIBUTING.md to include commands for Windows (GiorgosPapoutsakis, PR <a href="https://github.com/python/mypy/pull/17142">17142</a>)
</ul>
<h2>Other Notable Improvements and Fixes</h2>
<p><ul>
<li>Fix ParamSpec inference against TypeVarTuple (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17431">17431</a>)
<li>Fix explicit type for <tt>partial</tt> (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17424">17424</a>)
<li>Always allow lambda calls (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17430">17430</a>)
<li>Fix isinstance checks with PEP 604 unions containing None (Shantanu, PR <a href="https://github.com/python/mypy/pull/17415">17415</a>)
<li>Fix self-referential upper bound in new-style type variables (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17407">17407</a>)
<li>Consider overlap between instances and callables (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17389">17389</a>)
<li>Allow new-style self-types in classmethods (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17381">17381</a>)
<li>Fix isinstance with type aliases to PEP 604 unions (Shantanu, PR <a href="https://github.com/python/mypy/pull/17371">17371</a>)
<li>Properly handle unpacks in overlap checks (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17356">17356</a>)
<li>Fix type application for classes with generic constructors (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/17354">17354</a>)
<li>Update <tt>typing_extensions</tt> to >=4.6.0 to fix Python 3.12 error (Ben Brown, PR <a href="https://github.com/python/mypy/pull/17312">17312</a>)
<li>Avoid "does not return" error in lambda (Shantanu, PR <a href="https://github.com/python/mypy/pull/17294">17294</a>)
<li>Fix bug with descriptors in non-strict-optional mode (Max Murin, PR <a href="https://github.com/python/mypy/pull/17293">17293</a>)
<li>Don’t leak unreachability from lambda body to surrounding scope (Anders Kaseorg, PR <a href="https://github.com/python/mypy/pull/17287">17287</a>)
<li>Fix issues with non-ASCII characters on Windows (Alexander Leopold Shon, PR <a href="https://github.com/python/mypy/pull/17275">17275</a>)
<li>Fix for type narrowing of negative integer literals (gilesgc, PR <a href="https://github.com/python/mypy/pull/17256">17256</a>)
<li>Fix confusion between .py and .pyi files in mypy daemon (Valentin Stanciu, PR <a href="https://github.com/python/mypy/pull/17245">17245</a>)
<li>Fix type of <tt>tuple[X, Y]</tt> expression (urnest, PR <a href="https://github.com/python/mypy/pull/17235">17235</a>)
<li>Don't forget that a <tt>TypedDict</tt> was wrapped in <tt>Unpack</tt> after a <tt>name-defined</tt> error occurred (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/17226">17226</a>)
<li>Mark annotated argument as having an explicit, not inferred type (bzoracler, PR <a href="https://github.com/python/mypy/pull/17217">17217</a>)
<li>Don't consider Enum private attributes as enum members (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/17182">17182</a>)
<li>Fix Literal strings containing pipe characters (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/17148">17148</a>)
</ul>
<h2>Typeshed Updates</h2>
<p>Please see <a href="https://github.com/python/typeshed/commits/main?after=6dda799d8ad1d89e0f8aad7ac41d2d34bd838ace+0&branch=main&path=stdlib">git log</a> for full list of standard library typeshed stub changes.
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<p><ul>
<li>Alex Waygood
<li>Alexander Leopold Shon
<li>Ali Hamdan
<li>Anders Kaseorg
<li>Ben Brown
<li>Bénédikt Tran
<li>bzoracler
<li>Christoph Tyralla
<li>Christopher Barber
<li>dexterkennedy
<li>gilesgc
<li>GiorgosPapoutsakis
<li>Ivan Levkivskyi
<li>Jelle Zijlstra
<li>Jukka Lehtosalo
<li>Marc Mueller
<li>Matthieu Devlin
<li>Michael R. Crusoe
<li>Nikita Sobolev
<li>Seo Sanghyeon
<li>Shantanu
<li>sobolevn
<li>Steven Troxler
<li>Tadeu Manoel
<li>Tamir Duberstein
<li>Tushar Sadhwani
<li>urnest
<li>Valentin Stanciu
</ul>
<p>I’d also like to thank my employer, Dropbox, for supporting mypy development.</body>
</html>Max Murinhttp://www.blogger.com/profile/07972579056463365303noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-46096456268021556212024-04-24T06:56:00.000-07:002024-04-24T07:14:34.024-07:00Mypy 1.10 Released<html>
<meta charset="utf-8" />
<body>
<h1>Mypy 1.10 Released</h1>
<p>We’ve just uploaded mypy 1.10 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type checker for Python. This release includes new features, performance improvements and bug fixes. You can install it as follows:
<pre>
python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Support TypeIs (PEP 742)</h2>
<p>Mypy now supports <tt>TypeIs</tt> (<a href="https://peps.python.org/pep-0742/">PEP 742</a>), which allows
functions to narrow the type of a value, similar to <tt>isinstance()</tt>. Unlike <tt>TypeGuard</tt>,
<tt>TypeIs</tt> can narrow in both the <tt>if</tt> and <tt>else</tt> branches of an if statement:
<pre>
from typing_extensions import TypeIs
def is_str(s: object) -> TypeIs[str]:
return isinstance(s, str)
def f(o: str | int) -> None:
if is_str(o):
# Type of o is 'str'
...
else:
# Type of o is 'int'
...
</pre>
<tt>TypeIs</tt> will be added to the <tt>typing</tt> module in Python 3.13, but it
can be used on earlier Python versions by importing it from
<tt>typing_extensions</tt>.
<p>This feature was contributed by Jelle Zijlstra (PR <a href="https://github.com/python/mypy/pull/16898">16898</a>).
<h2>Support TypeVar Defaults (PEP 696)</h2>
<a href="https://peps.python.org/pep-0696/">PEP 696</a> adds support for type parameter defaults.
<p>Example:
<pre>
from typing import Generic
from typing_extensions import TypeVar
T = TypeVar("T", default=int)
class C(Generic[T]):
...
x: C = ...
y: C[str] = ...
reveal_type(x) # C[int], because of the default
reveal_type(y) # C[str]
</pre>
<p>TypeVar defaults will be added to the <tt>typing</tt> module in Python 3.13, but they
can be used with earlier Python releases by importing <tt>TypeVar</tt> from
<tt>typing_extensions</tt>.
<p>This feature was contributed by Marc Mueller (PR <a href="https://github.com/python/mypy/pull/16878">16878</a>
and PR <a href="https://github.com/python/mypy/pull/16925">16925</a>).
<h2>Support TypeAliasType (PEP 695)</h2>
<p>As part of the initial steps towards implementing <a href="https://peps.python.org/pep-0695/">PEP 695</a>, mypy now supports <tt>TypeAliasType</tt>.
<tt>TypeAliasType</tt> provides a backport of the new <tt>type</tt> statement in Python 3.12.
<pre>
type ListOrSet[T] = list[T] | set[T]
</pre>
is equivalent to:
<pre>
T = TypeVar("T")
ListOrSet = TypeAliasType("ListOrSet", list[T] | set[T], type_params=(T,))
</pre>
<p>Example of use in mypy:
<pre>
from typing_extensions import TypeAliasType, TypeVar
NewUnionType = TypeAliasType("NewUnionType", int | str)
x: NewUnionType = 42
y: NewUnionType = 'a'
z: NewUnionType = object()
# error: Incompatible types in assignment (expression has type "object",
# variable has type "int | str") [assignment]
T = TypeVar("T")
ListOrSet = TypeAliasType("ListOrSet", list[T] | set[T], type_params=(T,))
a: ListOrSet[int] = [1, 2]
b: ListOrSet[str] = {'a', 'b'}
c: ListOrSet[str] = 'test'
# error: Incompatible types in assignment (expression has type "str",
# variable has type "list[str] | set[str]") [assignment]
</pre>
<tt>TypeAliasType</tt> was added to the <tt>typing</tt> module in Python 3.12, but it can be used with earlier Python releases by importing from <tt>typing_extensions</tt>.
<p>This feature was contributed by Ali Hamdan (PR <a href="https://github.com/python/mypy/pull/16926">16926</a>, PR <a href="https://github.com/python/mypy/pull/17038">17038</a> and PR <a href="https://github.com/python/mypy/pull/17053">17053</a>)
<h2>Detect Additional Unsafe Uses of super()</h2>
<p>Mypy will reject unsafe uses of <tt>super()</tt> more consistently, when the target has a
trivial (empty) body. Example:
<pre>
class Proto(Protocol):
def method(self) -> int: ...
class Sub(Proto):
def method(self) -> int:
return super().meth() # Error (unsafe)
</pre>
<p>This feature was contributed by Shantanu (PR <a href="https://github.com/python/mypy/pull/16756">16756</a>).
<h2>Stubgen Improvements</h2>
<p><ul>
<li>Preserve empty tuple annotation (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/16907">16907</a>)
<li>Add support for PEP 570 positional-only parameters (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/16904">16904</a>)
<li>Replace obsolete typing aliases with builtin containers (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/16780">16780</a>)
<li>Fix generated dataclass <tt>__init__</tt> signature (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/16906">16906</a>)
</ul>
<h2>Mypyc Improvements</h2>
<p><ul>
<li>Provide an easier way to define IR-to-IR transforms (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/16998">16998</a>)
<li>Implement lowering pass and add primitives for int (in)equality (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17027">17027</a>)
<li>Implement lowering for remaining tagged integer comparisons (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17040">17040</a>)
<li>Optimize away some bool/bit registers (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17022">17022</a>)
<li>Remangle redefined names produced by async with (Richard Si, PR <a href="https://github.com/python/mypy/pull/16408">16408</a>)
<li>Optimize TYPE_CHECKING to False at Runtime (Srinivas Lade, PR <a href="https://github.com/python/mypy/pull/16263">16263</a>)
<li>Fix compilation of unreachable comprehensions (Richard Si, PR <a href="https://github.com/python/mypy/pull/15721">15721</a>)
<li>Don't crash on non-inlinable final local reads (Richard Si, PR <a href="https://github.com/python/mypy/pull/15719">15719</a>)
</ul>
<h2>Documentation Improvements</h2>
<p><ul>
<li>Import <tt>TypedDict</tt> from <tt>typing</tt> instead of <tt>typing_extensions</tt> (Riccardo Di Maio, PR <a href="https://github.com/python/mypy/pull/16958">16958</a>)
<li>Add missing <tt>mutable-override</tt> to section title (James Braza, PR <a href="https://github.com/python/mypy/pull/16886">16886</a>)
</ul>
<h2>Error Reporting Improvements</h2>
<p><ul>
<li>Use lower-case generics more consistently in error messages (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/17035">17035</a>)
</ul>
<h2>Other Notable Changes and Fixes</h2>
<p><ul>
<li>Fix incorrect inferred type when accessing descriptor on union type (Matthieu Devlin, PR <a href="https://github.com/python/mypy/pull/16604">16604</a>)
<li>Fix crash when expanding invalid <tt>Unpack</tt> in a <tt>Callable</tt> alias (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/17028">17028</a>)
<li>Fix false positive when string formatting with string enum (roberfi, PR <a href="https://github.com/python/mypy/pull/16555">16555</a>)
<li>Narrow individual items when matching a tuple to a sequence pattern (Loïc Simon, PR <a href="https://github.com/python/mypy/pull/16905">16905</a>)
<li>Fix false positive from type variable within TypeGuard or TypeIs (Evgeniy Slobodkin, PR <a href="https://github.com/python/mypy/pull/17071">17071</a>)
<li>Improve <tt>yield from</tt> inference for unions of generators (Shantanu, PR <a href="https://github.com/python/mypy/pull/16717">16717</a>)
<li>Fix emulating hash method logic in <tt>attrs</tt> classes (Hashem, PR <a href="https://github.com/python/mypy/pull/17016">17016</a>)
<li>Add reverted typeshed commit that uses <tt>ParamSpec</tt> for <tt>functools.wraps</tt> (Tamir Duberstein, PR <a href="https://github.com/python/mypy/pull/16942">16942</a>)
<li>Fix type narrowing for <tt>types.EllipsisType</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/17003">17003</a>)
<li>Fix single item enum match type exhaustion (Oskari Lehto, PR <a href="https://github.com/python/mypy/pull/16966">16966</a>)
<li>Improve type inference with empty collections (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/16994">16994</a>)
<li>Fix override checking for decorated property (Shantanu, PR <a href="https://github.com/python/mypy/pull/16856">16856</a>)
<li>Fix narrowing on match with function subject (Edward Paget, PR <a href="https://github.com/python/mypy/pull/16503">16503</a>)
<li>Allow <tt>+N</tt> within <tt>Literal[...]</tt> (Spencer Brown, PR <a href="https://github.com/python/mypy/pull/16910">16910</a>)
<li>Experimental: Support TypedDict within <tt>type[...]</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/16963">16963</a>)
<li>Experimtental: Fix issue with TypedDict with optional keys in <tt>type[...]</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/17068">17068</a>)
</ul>
<h2>Typeshed Updates</h2>
<p>Please see <a href="https://github.com/python/typeshed/commits/main?after=7c8e82fe483a40ec4cb0a2505cfdb0f3e7cc81d9+0&branch=main&path=stdlib">git log</a> for full list of standard library typeshed stub changes.
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<p><ul>
<li>Alex Waygood
<li>Ali Hamdan
<li>Edward Paget
<li>Evgeniy Slobodkin
<li>Hashem
<li>hesam
<li>Hugo van Kemenade
<li>Ihor
<li>James Braza
<li>Jelle Zijlstra
<li>jhance
<li>Jukka Lehtosalo
<li>Loïc Simon
<li>Marc Mueller
<li>Matthieu Devlin
<li>Michael R. Crusoe
<li>Nikita Sobolev
<li>Oskari Lehto
<li>Riccardo Di Maio
<li>Richard Si
<li>roberfi
<li>Roman Solomatin
<li>Sam Xifaras
<li>Shantanu
<li>Spencer Brown
<li>Srinivas Lade
<li>Tamir Duberstein
<li>youkaichao
</ul>
<p>I’d also like to thank my employer, Dropbox, for supporting mypy development.</body>
</html>Unknownnoreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-22789902648804234732024-03-08T08:15:00.000-08:002024-03-08T08:15:55.982-08:00Mypy 1.9 Released<p>
</p><h1>Mypy 1.9 Released</h1>
<p>We’ve just uploaded mypy 1.9 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type checker for Python. This release includes new features, performance improvements and bug fixes. You can install it as follows:
</p><pre> python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
</p><h2>Breaking Changes</h2>
<p>Because the version of typeshed we use in mypy 1.9 doesn't support 3.7, neither does mypy 1.9. (Jared Hance, PR <a href="https://github.com/python/mypy/pull/16883">16883</a>)
</p><p>We are planning to enable
<a href="https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-local-partial-types">local partial types</a> (enabled via the
<tt>--local-partial-types</tt> flag) later this year by default. This change
was announced years ago, but now it's finally happening. This is a
major backward-incompatible change, so we'll probably include it as
part of the upcoming mypy 2.0 release. This makes daemon and
non-daemon mypy runs have the same behavior by default.
</p><p>Local partial types can also be enabled in the mypy config file:
</p><pre> local_partial_types = True
</pre>
<p>We are looking at providing a tool to make it easier to migrate
projects to use <tt>--local-partial-types</tt>, but it's not yet clear whether
this is practical. The migration usually involves adding some
explicit type annotations to module-level and class-level variables.
</p><h2>Basic Support for Type Parameter Defaults (PEP 696)</h2>
<p>This release contains new experimental support for type parameter
defaults (<a href="https://peps.python.org/pep-0696">PEP 696</a>). Please try it
out! This feature was contributed by Marc Mueller.
</p><p>Since this feature will be officially introduced in the next Python
feature release (3.13), you will need to import <tt>TypeVar</tt>, <tt>ParamSpec</tt>
or <tt>TypeVarTuple</tt> from <tt>typing_extensions</tt> to use defaults for now.
</p><p>This example adapted from the PEP defines a default for <tt>BotT</tt>:
</p><pre> from typing import Generic
from typing_extensions import TypeVar
class Bot: ...
<p>BotT = TypeVar("BotT", bound=Bot, default=Bot)
class Context(Generic[BotT]):
bot: BotT
class MyBot(Bot): ...
# type is Bot (the default)
reveal_type(Context().bot)
# type is MyBot
reveal_type(Context<a href="">MyBot</a>.bot)
</pre>
<h2>Type-checking Improvements</h2>
<p></p><ul><li>Fix missing type store for overloads (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/16803">16803</a>)
</li><li>Fix <tt>'WriteToConn' object has no attribute 'flush'</tt> (Charlie Denton, PR <a href="https://github.com/python/mypy/pull/16801">16801</a>)
</li><li>Improve TypeAlias error messages (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/16831">16831</a>)
</li><li>Support narrowing unions that include <tt>type[None]</tt> (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/16315">16315</a>)
</li><li>Support TypedDict functional syntax as class base type (anniel-stripe, PR <a href="https://github.com/python/mypy/pull/16703">16703</a>)
</li><li>Accept multiline quoted annotations (Shantanu, PR <a href="https://github.com/python/mypy/pull/16765">16765</a>)
</li><li>Allow unary + in <tt>Literal</tt> (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/16729">16729</a>)
</li><li>Substitute type variables in return type of static methods (Kouroche Bouchiat, PR <a href="https://github.com/python/mypy/pull/16670">16670</a>)
</li><li>Consider TypeVarTuple to be invariant (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/16759">16759</a>)
</li><li>Add <tt>alias</tt> support to <tt>field()</tt> in <tt>attrs</tt> plugin (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/16610">16610</a>)
</li><li>Improve attrs hashability detection (Tin Tvrtković, PR <a href="https://github.com/python/mypy/pull/16556">16556</a>)
</li></ul>
<h2>Performance Improvements</h2>
<p></p><ul><li>Speed up finding function type variables (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/16562">16562</a>)
</li></ul>
<h2>Documentation Updates</h2>
<p></p><ul><li>Document supported values for <tt>--enable-incomplete-feature</tt> in "mypy --help" (Froger David, PR <a href="https://github.com/python/mypy/pull/16661">16661</a>)
</li><li>Update new type system discussion links (thomaswhaley, PR <a href="https://github.com/python/mypy/pull/16841">16841</a>)
</li><li>Add missing class instantiation to cheat sheet (Aleksi Tarvainen, PR <a href="https://github.com/python/mypy/pull/16817">16817</a>)
</li><li>Document how evil <tt>--no-strict-optional</tt> is (Shantanu, PR <a href="https://github.com/python/mypy/pull/16731">16731</a>)
</li><li>Improve mypy daemon documentation note about local partial types (Makonnen Makonnen, PR <a href="https://github.com/python/mypy/pull/16782">16782</a>)
</li><li>Fix numbering error (Stefanie Molin, PR <a href="https://github.com/python/mypy/pull/16838">16838</a>)
</li><li>Various documentation improvements (Shantanu, PR <a href="https://github.com/python/mypy/pull/16836">16836</a>)
</li></ul>
<h2>Stubtest Improvements</h2>
<p></p><ul><li>Ignore private function/method parameters when they are missing from the stub (private parameter names start with a single underscore and have a default, PR <a href="https://github.com/python/mypy/pull/16507">16507</a>)
</li><li>Ignore a new protocol dunder (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/16895">16895</a>)
</li><li>Private parameters can be omitted (Sebastian Rittau, PR <a href="https://github.com/python/mypy/pull/16507">16507</a>)
</li><li>Add support for setting enum members to "..." (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/16807">16807</a>)
</li><li>Adjust symbol table logic (Shantanu, PR <a href="https://github.com/python/mypy/pull/16823">16823</a>)
</li><li>Fix posisitional-only handling in overload resolution (Shantanu, PR <a href="https://github.com/python/mypy/pull/16750">16750</a>)
</li></ul>
<h2>Stubgen Improvements</h2>
<p></p><ul><li>Fix crash on star unpack of TypeVarTuple (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/16869">16869</a>)
</li><li>Use PEP 604 unions everywhere (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/16519">16519</a>)
</li><li>Do not ignore property deleter (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/16781">16781</a>)
</li><li>Support type stub generation for <tt>staticmethod</tt> (WeilerMarcel, PR <a href="https://github.com/python/mypy/pull/14934">14934</a>)
</li></ul>
<h2>Acknowledgements</h2>
Thanks to all mypy contributors who contributed to this release:
<p></p><ul><li>Aleksi Tarvainen
</li><li>Alex Waygood
</li><li>Ali Hamdan
</li><li>anniel-stripe
</li><li>Charlie Denton
</li><li>Christoph Tyralla
</li><li>Dheeraj
</li><li>Fabian Keller
</li><li>Fabian Lewis
</li><li>Froger David
</li><li>Ihor
</li><li>Jared Hance
</li><li>Jelle Zijlstra
</li><li>Jukka Lehtosalo
</li><li>Kouroche Bouchiat
</li><li>Lukas Geiger
</li><li>Maarten Huijsmans
</li><li>Makonnen Makonnen
</li><li>Marc Mueller
</li><li>Nikita Sobolev
</li><li>Sebastian Rittau
</li><li>Shantanu
</li><li>Stefanie Molin
</li><li>Stephen Morton
</li><li>thomaswhaley
</li><li>Tin Tvrtković
</li><li>WeilerMarcel
</li><li>Wesley Collin Wright
</li><li>zipperer
</li></ul>
<p>I’d also like to thank my employer, Dropbox, for supporting mypy development.
</p>Jared Hancehttp://www.blogger.com/profile/13451114101069297635noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-49315324001524235142023-12-21T08:37:00.000-08:002023-12-21T08:37:41.590-08:00Mypy 1.8 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 1.8 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type checker for Python. This release includes new features, performance improvements and bug fixes. You can install it as follows:
<pre>
python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Type-checking Improvements</h2>
<p><ul>
<li>Do not intersect types in isinstance checks if at least one is final (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/16330">16330</a>)
<li>Detect that <tt>@final</tt> class without <tt>__bool__</tt> cannot have falsey instances (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/16566">16566</a>)
<li>Do not allow <tt>TypedDict</tt> classes with extra keywords (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/16438">16438</a>)
<li>Do not allow class-level keywords for <tt>NamedTuple</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/16526">16526</a>)
<li>Make imprecise constraints handling more robust (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16502">16502</a>)
<li>Fix strict-optional in extending generic TypedDict (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16398">16398</a>)
<li>Allow type ignores of PEP 695 constructs (Shantanu, PR <a href="https://github.com/python/mypy/pull/16608">16608</a>)
<li>Enable <tt>type_check_only</tt> support for <tt>TypedDict</tt> and <tt>NamedTuple</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/16469">16469</a>)
</ul>
<h2>Performance Improvements</h2>
<p><ul>
<li>Add fast path to analyzing special form assignments (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/16561">16561</a>)
</ul>
<h2>Improvements to Error Reporting</h2>
<p><ul>
<li>Don't show documentation links for plugin error codes (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16383">16383</a>)
<li>Improve error messages for <tt>super</tt> checks and add more tests (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/16393">16393</a>)
<li>Add error code for mutable covariant override (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16399">16399</a>)
</ul>
<h2>Stubgen Improvements</h2>
<p><ul>
<li>Preserve simple defaults in function signatures (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/15355">15355</a>)
<li>Include <tt>__all__</tt> in output (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/16356">16356</a>)
<li>Fix stubgen regressions with pybind11 and mypy 1.7 (Chad Dombrova, PR <a href="https://github.com/python/mypy/pull/16504">16504</a>)
</ul>
<h2>Stubtest Improvements</h2>
<p><ul>
<li>Improve handling of unrepresentable defaults (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/16433">16433</a>)
<li>Print more helpful errors if a function is missing from stub (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/16517">16517</a>)
<li>Support <tt>@type_check_only</tt> decorator (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/16422">16422</a>)
<li>Warn about missing <tt>__del__</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/16456">16456</a>)
<li>Fix crashes with some uses of <tt>final</tt> and <tt>deprecated</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/16457">16457</a>)
</ul>
<h2>Fixes to Crashes</h2>
<p><ul>
<li>Fix crash with type alias to <tt>Callable[[Unpack[Tuple[Any, ...]]], Any]</tt> (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/16541">16541</a>)
<li>Fix crash on TypeGuard in <tt>__call__</tt> (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16516">16516</a>)
<li>Fix crash on invalid enum in method (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16511">16511</a>)
<li>Fix crash on unimported Any in TypedDict (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16510">16510</a>)
</ul>
<h2>Documentation Updates</h2>
<p><ul>
<li>Update soft-error-limit default value to -1 (Sveinung Gundersen, PR <a href="https://github.com/python/mypy/pull/16542">16542</a>)
<li>Support Sphinx 7.x (Michael R. Crusoe, PR <a href="https://github.com/python/mypy/pull/16460">16460</a>)
</ul>
<h2>Other Notable Changes and Fixes</h2>
<p><ul>
<li>Allow mypy to output a junit file with per-file results (Matthew Wright, PR <a href="https://github.com/python/mypy/pull/16388">16388</a>)
</ul>
<h2>Typeshed Updates</h2>
<p>Please see <a href="https://github.com/python/typeshed/commits/main?after=4a854366e03dee700109f8e758a08b2457ea2f51+0&branch=main&path=stdlib">git log</a> for full list of standard library typeshed stub changes.
<h2>Acknowledgements</h2>
Thanks to all mypy contributors who contributed to this release:
<p><ul>
<li>Alex Waygood
<li>Ali Hamdan
<li>Chad Dombrova
<li>Christoph Tyralla
<li>Ilya Priven
<li>Ivan Levkivskyi
<li>Jelle Zijlstra
<li>Jukka Lehtosalo
<li>Marcel Telka
<li>Matthew Wright
<li>Michael R. Crusoe
<li>Nikita Sobolev
<li>Ole Peder Brandtzæg
<li>robjhornby
<li>Shantanu
<li>Sveinung Gundersen
<li>Valentin Stanciu
</ul>
<p>I’d also like to thank my employer, Dropbox, for supporting mypy development.
<p>Posted by Wesley Collin Wright</body>
</html>Unknownnoreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-83699255276618136262023-11-10T06:38:00.002-08:002023-11-10T07:08:12.468-08:00Mypy 1.7 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 1.7 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type checker for Python. This release includes new features, performance improvements and bug fixes. You can install it as follows:
<pre>
python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Using TypedDict for <tt>**kwargs</tt> Typing</h2>
<p>Mypy now has support for using <tt>Unpack[...]</tt> with a TypedDict type to annotate <tt>**kwargs</tt> arguments enabled by default. Example:
<pre>
# Or 'from typing_extensions import ...'
from typing import TypedDict, Unpack
class Person(TypedDict):
name: str
age: int
def foo(**kwargs: Unpack[Person]) -> None:
...
foo(name="x", age=1) # Ok
foo(name=1) # Error
</pre>
<p>The definition of <tt>foo</tt> above is equivalent to the one below, with keyword-only arguments <tt>name</tt> and <tt>age</tt>:
<pre>
def foo(*, name: str, age: int) -> None:
...
</pre>
<p>Refer to <a href="https://peps.python.org/pep-0692/">PEP 692</a> for more information. Note that unlike in the current version of the PEP, mypy always treats signatures with <tt>Unpack[SomeTypedDict]</tt> as equivalent to their expanded forms with explicit keyword arguments, and there aren't special type checking rules for TypedDict arguments.
<p>This was contributed by Ivan Levkivskyi back in 2022 (PR <a href="https://github.com/python/mypy/pull/13471">13471</a>).
<h2>TypeVarTuple Support Enabled (Experimental)</h2>
<p>Mypy now has support for variadic generics (TypeVarTuple) enabled by default, as an experimental feature. Refer to <a href="https://peps.python.org/pep-0646/">PEP 646</a> for the details.
<p>TypeVarTuple was implemented by Jared Hance and Ivan Levkivskyi over several mypy releases, with help from Jukka Lehtosalo.
<p>Changes included in this release:
<p><ul>
<li>Fix handling of tuple type context with unpacks (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16444">16444</a>)
<li>Handle TypeVarTuples when checking overload constraints (robjhornby, PR <a href="https://github.com/python/mypy/pull/16428">16428</a>)
<li>Enable Unpack/TypeVarTuple support (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16354">16354</a>)
<li>Fix crash on unpack call special-casing (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16381">16381</a>)
<li>Some final touches for variadic types support (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16334">16334</a>)
<li>Support PEP-646 and PEP-692 in the same callable (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16294">16294</a>)
<li>Support new <tt>*</tt> syntax for variadic types (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16242">16242</a>)
<li>Correctly handle variadic instances with empty arguments (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16238">16238</a>)
<li>Correctly handle runtime type applications of variadic types (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16240">16240</a>)
<li>Support variadic tuple packing/unpacking (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16205">16205</a>)
<li>Better support for variadic calls and indexing (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16131">16131</a>)
<li>Subtyping and inference of user-defined variadic types (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16076">16076</a>)
<li>Complete type analysis of variadic types (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15991">15991</a>)
</ul>
<h2>New Way of Installing Mypyc Dependencies</h2>
<p>If you want to install package dependencies needed by mypyc (not just mypy), you should now install <tt>mypy[mypyc]</tt> instead of just <tt>mypy</tt>:
<pre>
python3 -m pip install -U 'mypy[mypyc]'
</pre>
<p>Mypy has many more users than mypyc, so always installing mypyc dependencies would often bring unnecessary dependencies.
<p>This change was contributed by Shantanu (PR <a href="https://github.com/python/mypy/pull/16229">16229</a>).
<h2>New Rules for Re-exports</h2>
<p>Mypy no longer considers an import such as <tt>import a.b as b</tt> as an explicit re-export. The old behavior was arguably inconsistent and surprising. This may impact some stub packages, such as older versions of <tt>types-six</tt>. You can change the import to <tt>from a import b as b</tt>, if treating the import as a re-export was intentional.
<p>This change was contributed by Anders Kaseorg (PR <a href="https://github.com/python/mypy/pull/14086">14086</a>).
<h2>Improved Type Inference</h2>
<p>The new type inference algorithm that was recently introduced to mypy (but was not enabled by default) is now enabled by default. It improves type inference of calls to generic callables where an argument is also a generic callable, in particular. You can use <tt>--old-type-inference</tt> to disable the new behavior.
<p>The new algorithm can (rarely) produce different error messages, different error codes, or errors reported on different lines. This is more likely in cases where generic types were used incorrectly.
<p>The new type inference algorithm was contributed by Ivan Levkivskyi. PR <a href="https://github.com/python/mypy/pull/16345">16345</a> enabled it by default.
<h2>Narrowing Tuple Types Using len()</h2>
<p>Mypy now can narrow tuple types using <tt>len()</tt> checks. Example:
<pre>
def f(t: tuple[int, int] | tuple[int, int, int]) -> None:
if len(t) == 2:
a, b = t # Ok
...
</pre>
<p>This feature was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/16237">16237</a>).
<h2>More Precise Tuple Lengths (Experimental)</h2>
<p>Mypy supports experimental, more precise checking of tuple type lengths through <tt>--enable-incomplete-feature=PreciseTupleTypes</tt>. Refer to the <a href="https://mypy.readthedocs.io/en/latest/command_line.html#enabling-incomplete-experimental-features">documentation</a> for more information.
<p>More generally, we are planning to use <tt>--enable-incomplete-feature</tt> to introduce experimental features that would benefit from community feedback.
<p>This feature was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/16237">16237</a>).
<h2>Mypy Changelog</h2>
<p>We now maintain a <a href="https://github.com/python/mypy/blob/master/CHANGELOG.md">changelog</a> in the mypy Git repository. It mirrors the contents of <a href="https://mypy-lang.blogspot.com/">mypy release blog posts</a>. We will continue to also publish release blog posts. In the future, release blog posts will be created based on the changelog near a release date.
<p>This was contributed by Shantanu (PR <a href="https://github.com/python/mypy/pull/16280">16280</a>).
<h2>Mypy Daemon Improvements</h2>
<p><ul>
<li>Fix daemon crash caused by deleted submodule (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/16370">16370</a>)
<li>Fix file reloading in dmypy with --export-types (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16359">16359</a>)
<li>Fix dmypy inspect on Windows (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16355">16355</a>)
<li>Fix dmypy inspect for namespace packages (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16357">16357</a>)
<li>Fix return type change to optional in generic function (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/16342">16342</a>)
<li>Fix daemon false positives related to module-level <tt>__getattr__</tt> (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/16292">16292</a>)
<li>Fix daemon crash related to ABCs (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/16275">16275</a>)
<li>Stream dmypy output instead of dumping everything at the end (Valentin Stanciu, PR <a href="https://github.com/python/mypy/pull/16252">16252</a>)
<li>Make sure all dmypy errors are shown (Valentin Stanciu, PR <a href="https://github.com/python/mypy/pull/16250">16250</a>)
</ul>
<h2>Mypyc Improvements</h2>
<p><ul>
<li>Generate error on duplicate function definitions (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/16309">16309</a>)
<li>Don't crash on unreachable statements (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/16311">16311</a>)
<li>Avoid cyclic reference in nested functions (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/16268">16268</a>)
<li>Fix direct <tt>__dict__</tt> access on inner functions in new Python (Shantanu, PR <a href="https://github.com/python/mypy/pull/16084">16084</a>)
<li>Make tuple packing and unpacking more efficient (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/16022">16022</a>)
</ul>
<h2>Improvements to Error Reporting</h2>
<p><ul>
<li>Update starred expression error message to match CPython (Cibin Mathew, PR <a href="https://github.com/python/mypy/pull/16304">16304</a>)
<li>Fix error code of "Maybe you forgot to use await" note (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/16203">16203</a>)
<li>Use error code <tt>[unsafe-overload]</tt> for unsafe overloads, instead of <tt>[misc]</tt> (Randolf Scholz, PR <a href="https://github.com/python/mypy/pull/16061">16061</a>)
<li>Reword the error message related to void functions (Albert Tugushev, PR <a href="https://github.com/python/mypy/pull/15876">15876</a>)
<li>Represent bottom type as Never in messages (Shantanu, PR <a href="https://github.com/python/mypy/pull/15996">15996</a>)
<li>Add hint for AsyncIterator incompatible return type (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/15883">15883</a>)
<li>Don't suggest stubs packages where the runtime package now ships with types (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/16226">16226</a>)
</ul>
<h2>Performance Improvements</h2>
<p><ul>
<li>Speed up type argument checking (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/16353">16353</a>)
<li>Add fast path for checking self types (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/16352">16352</a>)
<li>Cache information about whether file is typeshed file (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/16351">16351</a>)
<li>Skip expensive <tt>repr()</tt> in logging call when not needed (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/16350">16350</a>)
</ul>
<h2>Attrs and Dataclass Improvements</h2>
<p><ul>
<li><tt>dataclass.replace</tt>: Allow transformed classes (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/15915">15915</a>)
<li><tt>dataclass.replace</tt>: Fall through to typeshed signature (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/15962">15962</a>)
<li>Document <tt>dataclass_transform</tt> behavior (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/16017">16017</a>)
<li><tt>attrs</tt>: Remove fields type check (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/15983">15983</a>)
<li><tt>attrs</tt>, <tt>dataclasses</tt>: Don't enforce slots when base class doesn't (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/15976">15976</a>)
<li>Fix crash on dataclass field / property collision (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/16147">16147</a>)
</ul>
<h2>Stubgen Improvements</h2>
<p><ul>
<li>Write stubs with utf-8 encoding (Jørgen Lind, PR <a href="https://github.com/python/mypy/pull/16329">16329</a>)
<li>Fix missing property setter in semantic analysis mode (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/16303">16303</a>)
<li>Unify C extension and pure python stub generators with object oriented design (Chad Dombrova, PR <a href="https://github.com/python/mypy/pull/15770">15770</a>)
<li>Multiple fixes to the generated imports (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/15624">15624</a>)
<li>Generate valid dataclass stubs (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/15625">15625</a>)
</ul>
<h2>Fixes to Crashes</h2>
<p><ul>
<li>Fix incremental mode crash on TypedDict in method (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16364">16364</a>)
<li>Fix crash on star unpack in TypedDict (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16116">16116</a>)
<li>Fix crash on malformed TypedDict in incremental mode (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16115">16115</a>)
<li>Fix crash with report generation on namespace packages (Shantanu, PR <a href="https://github.com/python/mypy/pull/16019">16019</a>)
<li>Fix crash when parsing error code config with typo (Shantanu, PR <a href="https://github.com/python/mypy/pull/16005">16005</a>)
<li>Fix <tt>__post_init__()</tt> internal error (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/16080">16080</a>)
</ul>
<h2>Documentation Updates</h2>
<p><ul>
<li>Make it easier to copy commands from README (Hamir Mahal, PR <a href="https://github.com/python/mypy/pull/16133">16133</a>)
<li>Document and rename <tt>[overload-overlap]</tt> error code (Shantanu, PR <a href="https://github.com/python/mypy/pull/16074">16074</a>)
<li>Document <tt>--force-uppercase-builtins</tt> and <tt>--force-union-syntax</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/16049">16049</a>)
<li>Document <tt>force_union_syntax</tt> and <tt>force_uppercase_builtins</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/16048">16048</a>)
<li>Document we're not tracking relationships between symbols (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/16018">16018</a>)
</ul>
<h2>Other Notable Changes and Fixes</h2>
<p><ul>
<li>Propagate narrowed types to lambda expressions (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16407">16407</a>)
<li>Avoid importing from <tt>setuptools._distutils</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/16348">16348</a>)
<li>Delete recursive aliases flags (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16346">16346</a>)
<li>Properly use proper subtyping for callables (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16343">16343</a>)
<li>Use upper bound as inference fallback more consistently (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16344">16344</a>)
<li>Add <tt>[unimported-reveal]</tt> error code (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/16271">16271</a>)
<li>Add <tt>|=</tt> and <tt>|</tt> operators support for <tt>TypedDict</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/16249">16249</a>)
<li>Clarify variance convention for Parameters (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16302">16302</a>)
<li>Correctly recognize <tt>typing_extensions.NewType</tt> (Ganden Schaffner, PR <a href="https://github.com/python/mypy/pull/16298">16298</a>)
<li>Fix partially defined in the case of missing type maps (Shantanu, PR <a href="https://github.com/python/mypy/pull/15995">15995</a>)
<li>Use SPDX license identifier (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/16230">16230</a>)
<li>Make <tt>__qualname__</tt> and <tt>__module__</tt> available in class bodies (Anthony Sottile, PR <a href="https://github.com/python/mypy/pull/16215">16215</a>)
<li>stubtest: Hint when args in stub need to be keyword-only (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/16210">16210</a>)
<li>Tuple slice should not propagate fallback (Thomas Grainger, PR <a href="https://github.com/python/mypy/pull/16154">16154</a>)
<li>Fix cases of type object handling for overloads (Shantanu, PR <a href="https://github.com/python/mypy/pull/16168">16168</a>)
<li>Fix walrus interaction with empty collections (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16197">16197</a>)
<li>Use type variable bound when it appears as actual during inference (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16178">16178</a>)
<li>Use upper bounds as fallback solutions for inference (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16184">16184</a>)
<li>Special-case type inference of empty collections (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16122">16122</a>)
<li>Allow TypedDict unpacking in Callable types (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/16083">16083</a>)
<li>Fix inference for overloaded <tt>__call__</tt> with generic self (Shantanu, PR <a href="https://github.com/python/mypy/pull/16053">16053</a>)
<li>Call dynamic class hook on generic classes (Petter Friberg, PR <a href="https://github.com/python/mypy/pull/16052">16052</a>)
<li>Preserve implicitly exported types via attribute access (Shantanu, PR <a href="https://github.com/python/mypy/pull/16129">16129</a>)
<li>Fix a stubtest bug (Alex Waygood)
<li>Fix <tt>tuple[Any, ...]</tt> subtyping (Shantanu, PR <a href="https://github.com/python/mypy/pull/16108">16108</a>)
<li>Lenient handling of trivial Callable suffixes (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15913">15913</a>)
<li>Add <tt>add_overloaded_method_to_class</tt> helper for plugins (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/16038">16038</a>)
<li>Bundle <tt>misc/proper_plugin.py</tt> as a part of <tt>mypy</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/16036">16036</a>)
<li>Fix <tt>case Any()</tt> in match statement (DS/Charlie, PR <a href="https://github.com/python/mypy/pull/14479">14479</a>)
<li>Make iterable logic more consistent (Shantanu, PR <a href="https://github.com/python/mypy/pull/16006">16006</a>)
<li>Fix inference for properties with <tt>__call__</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/15926">15926</a>)
</ul>
<h2>Typeshed Updates</h2>
<p>Please see <a href="https://github.com/python/typeshed/commits/main?after=4a854366e03dee700109f8e758a08b2457ea2f51+0&branch=main&path=stdlib">git log</a> for full list of standard library typeshed stub changes.
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<p><ul>
<li>Albert Tugushev
<li>Alex Waygood
<li>Ali Hamdan
<li>Anders Kaseorg
<li>Anthony Sottile
<li>Chad Dombrova
<li>Cibin Mathew
<li>dinaldoap
<li>DS/Charlie
<li>Eli Schwartz
<li>Ganden Schaffner
<li>Hamir Mahal
<li>Ihor
<li>Ikko Eltociear Ashimine
<li>Ilya Priven
<li>Ivan Levkivskyi
<li>Jelle Zijlstra
<li>Jukka Lehtosalo
<li>Jørgen Lind
<li>KotlinIsland
<li>Matt Bogosian
<li>Nikita Sobolev
<li>Petter Friberg
<li>Randolf Scholz
<li>Shantanu
<li>Thomas Grainger
<li>Valentin Stanciu
</ul>
<p>I’d also like to thank my employer, Dropbox, for supporting mypy development.
</body>
</html>Jukka Lehtosalohttp://www.blogger.com/profile/00122775610277203624noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-50846709184025997782023-10-10T10:50:00.000-07:002023-10-10T10:50:06.657-07:00Mypy 1.6 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 1.6 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type checker for Python. This release includes new features, performance improvements and bug fixes. You can install it as follows:
<pre>
python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Introduce Error Subcodes for Import Errors</h2>
<p>Mypy now uses the error code <tt>import-untyped</tt> if an import targets an installed library that doesn’t support static type checking, and no stub files are available. Other invalid imports produce the <tt>import-not-found</tt> error code. They both are subcodes of the <tt>import</tt> error code, which was previously used for both kinds of import-related errors.
<p>Use <tt>--disable-error-code=import-untyped</tt> to only ignore import errors about installed libraries without stubs. This way mypy will still report errors about typos in import statements, for example.
<p>If you use <tt>--warn-unused-ignore</tt> or <tt>--strict</tt>, mypy will complain if you use <tt># type: ignore[import]</tt> to ignore an import error. You are expected to use one of the more specific error codes instead. Otherwise, ignoring the <tt>import</tt> error code continues to silence both errors.
<p>This feature was contributed by Shantanu (PR <a href="https://github.com/python/mypy/pull/15840">15840</a>, PR <a href="https://github.com/python/mypy/pull/14740">14740</a>).
<h2>Remove Support for Targeting Python 3.6 and Earlier</h2>
<p>Running mypy with <tt>--python-version 3.6</tt>, for example, is no longer supported. Python 3.6 hasn’t been properly supported by mypy for some time now, and this makes it explicit. This was contributed by Nikita Sobolev (PR <a href="https://github.com/python/mypy/pull/15668">15668</a>).
<h2>Selective Filtering of <tt>--disallow-untyped-calls</tt> Targets</h2>
<p>Using <tt>--disallow-untyped-calls</tt> could be annoying when using libraries with missing type information, as mypy would generate many errors about code that uses the library. Now you can use <tt>--untyped-calls-exclude=acme</tt>, for example, to disable these errors about calls targeting functions defined in the <tt>acme</tt> package. Refer to the <a href="https://mypy.readthedocs.io/en/latest/command_line.html#cmdoption-mypy-untyped-calls-exclude">documentation</a> for more information.
<p>This feature was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/15845">15845</a>).
<h2>Improved Type Inference between Callable Types</h2>
<p>Mypy now does a better job inferring type variables inside arguments of callable types. For example, this code fragment now type checks correctly:
<pre>
def f(c: Callable[[T, S], None]) -> Callable[[str, T, S], None]: ...
def g(*x: int) -> None: ...
reveal_type(f(g)) # Callable[[str, int, int], None]
</pre>
<p>This was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/15910">15910</a>).
<h2>Don’t Consider None and TypeVar to Overlap in Overloads</h2>
<p>Mypy now doesn’t consider an overload item with an argument type <tt>None</tt> to overlap with a type variable:
<pre>
@overload
def f(x: None) -> None: ..
@overload
def f(x: T) -> Foo[T]: ...
...
</pre>
<p>Previously mypy would generate an error about the definition of <tt>f</tt> above. This is slightly unsafe if the upper bound of <tt>T</tt> is <tt>object</tt>, since the value of the type variable could be <tt>None</tt>. We relaxed the rules a little, since this solves a common issue.
<p>This feature was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/15846">15846</a>).
<h2>Improvements to <tt>--</tt><tt>new-type-inference</tt></h2>
<p>The experimental new type inference algorithm (polymorphic inference) introduced as an opt-in feature in mypy 1.5 has several improvements:
<ul>
<li>Improve transitive closure computation during constraint solving (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15754">15754</a>)
<li>Add support for upper bounds and values with <tt>--new-type-inference</tt> (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15813">15813</a>)
<li>Basic support for variadic types with <tt>--new-type-inference</tt> (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15879">15879</a>)
<li>Polymorphic inference: support for parameter specifications and lambdas (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15837">15837</a>)
<li>Invalidate cache when adding <tt>--new-type-inference</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/16059">16059</a>)
</ul>
<p><b>Note:</b> We are planning to enable <tt>--new-type-inference</tt> by default in mypy 1.7. Please try this out and let us know if you encounter any issues.
<h2>ParamSpec Improvements</h2>
<ul>
<li>Support self-types containing ParamSpec (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15903">15903</a>)
<li>Allow “…” in Concatenate, and clean up ParamSpec literals (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15905">15905</a>)
<li>Fix ParamSpec inference for callback protocols (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15986">15986</a>)
<li>Infer ParamSpec constraint from arguments (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15896">15896</a>)
<li>Fix crash on invalid type variable with ParamSpec (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15953">15953</a>)
<li>Fix subtyping between ParamSpecs (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15892">15892</a>)
</ul>
<h2>Stubgen Improvements</h2>
<ul>
<li>Add option to include docstrings with stubgen (chylek, PR <a href="https://github.com/python/mypy/pull/13284">13284</a>)
<li>Add required <tt>...</tt> initializer to <tt>NamedTuple</tt> fields with default values (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/15680">15680</a>)
</ul>
<h2>Stubtest Improvements</h2>
<ul>
<li>Fix <tt>__mypy-replace</tt> false positives (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/15689">15689</a>)
<li>Fix edge case for <tt>bytes</tt> enum subclasses (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/15943">15943</a>)
<li>Generate error if typeshed is missing modules from the stdlib (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/15729">15729</a>)
<li>Fixes to new check for missing stdlib modules (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/15960">15960</a>)
<li>Fix stubtest <tt>enum.Flag</tt> edge case (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/15933">15933</a>)
</ul>
<h2>Documentation Improvements</h2>
<ul>
<li>Do not advertise to create your own <tt>assert_never</tt> helper (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/15947">15947</a>)
<li>Fix all the missing references found within the docs (Albert Tugushev, PR <a href="https://github.com/python/mypy/pull/15875">15875</a>)
<li>Document <tt>await-not-async</tt> error code (Shantanu, PR <a href="https://github.com/python/mypy/pull/15858">15858</a>)
<li>Improve documentation of disabling error codes (Shantanu, PR <a href="https://github.com/python/mypy/pull/15841">15841</a>)
</ul>
<h2>Other Notable Changes and Fixes</h2>
<ul>
<li>Make unsupported PEP 695 features (introduced in Python 3.12) give a reasonable error message (Shantanu, PR <a href="https://github.com/python/mypy/pull/16013">16013</a>)
<li>Remove the <tt>--py2</tt> command-line argument (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/15670">15670</a>)
<li>Change empty tuple from <tt>tuple[]</tt> to <tt>tuple[()]</tt> in error messages (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/15783">15783</a>)
<li>Fix <tt>assert_type</tt> failures when some nodes are deferred (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/15920">15920</a>)
<li>Generate error on unbound TypeVar with values (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/15732">15732</a>)
<li>Fix over-eager <tt>types-google-cloud-ndb</tt> suggestion (Shantanu, PR <a href="https://github.com/python/mypy/pull/15347">15347</a>)
<li>Fix type narrowing of <tt>== None</tt> and <tt>in (None,)</tt> conditions (Marti Raudsepp, PR <a href="https://github.com/python/mypy/pull/15760">15760</a>)
<li>Fix inference for <tt>attrs.fields</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/15688">15688</a>)
<li>Make “await in non-async function” a non-blocking error and give it an error code (Gregory Santosa, PR <a href="https://github.com/python/mypy/pull/15384">15384</a>)
<li>Add basic support for decorated overloads (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15898">15898</a>)
<li>Fix TypeVar regression with self types (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15945">15945</a>)
<li>Add <tt>__match_args__</tt> to dataclasses with no fields (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/15749">15749</a>)
<li>Include stdout and stderr in dmypy verbose output (Valentin Stanciu, PR <a href="https://github.com/python/mypy/pull/15881">15881</a>)
<li>Improve match narrowing and reachability analysis (Shantanu, PR <a href="https://github.com/python/mypy/pull/15882">15882</a>)
<li>Support <tt>__bool__</tt> with <tt>Literal</tt> in <tt>--warn-unreachable</tt> (Jannic Warken, PR <a href="https://github.com/python/mypy/pull/15645">15645</a>)
<li>Fix inheriting from generic <tt>@frozen</tt> attrs class (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/15700">15700</a>)
<li>Correctly narrow types for <tt>tuple[type[X], ...]</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/15691">15691</a>)
<li>Don't flag intentionally empty generators unreachable (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/15722">15722</a>)
<li>Add tox.ini to mypy sdist (Marcel Telka, PR <a href="https://github.com/python/mypy/pull/15853">15853</a>)
<li>Fix mypyc regression with pretty (Shantanu, PR <a href="https://github.com/python/mypy/pull/16124">16124</a>)
</ul>
<h2>Typeshed Updates</h2>
<p>Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see <a href="https://github.com/python/typeshed/commits/main?after=6a8d653a671925b0a3af61729ff8cf3f90c9c662+0&branch=main&path=stdlib">git log</a> for full list of typeshed changes.
<h2>Acknowledgements</h2>
<p>Thanks to Max Murin, who did most of the release manager work for this release (I just did
the final steps).
<p>Thanks to all mypy contributors who contributed to this release:
<ul>
<li>Albert Tugushev
<li>Alex Waygood
<li>Ali Hamdan
<li>chylek
<li>EXPLOSION
<li>Gregory Santosa
<li>Ilya Priven
<li>Ivan Levkivskyi
<li>Jannic Warken
<li>KotlinIsland
<li>Marc Mueller
<li>Marcel Johannesmann
<li>Marcel Telka
<li>Mark Byrne
<li>Marti Raudsepp
<li>Max Murin
<li>Nikita Sobolev
<li>Shantanu
<li>Valentin Stanciu
</ul></body>
</html>Jukka Lehtosalohttp://www.blogger.com/profile/00122775610277203624noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-42428293280940260342023-08-10T05:59:00.001-07:002023-08-10T12:11:47.059-07:00Mypy 1.5 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 1.5 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type checker for Python. This release includes new features, deprecations and bug fixes. You can install it as follows:
<pre>
python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Drop Support for Python 3.7</h2>
<p>Mypy no longer supports running with Python 3.7, which has reached end-of-life. This was contributed by Shantanu (PR <a href="https://github.com/python/mypy/pull/15566">15566</a>).
<h2>Optional Check to Require Explicit @override</h2>
<p>If you enable the <tt>explicit-override</tt> error code, mypy will generate an error if a method override doesn’t use the <tt>@typing.override</tt> decorator (as discussed in <a href="https://peps.python.org/pep-0698/#strict-enforcement-per-project">PEP 698</a>). This way mypy will detect accidentally introduced overrides. Example:
<pre>
# mypy: enable-error-code="explicit-override"
from typing_extensions import override
class C:
def foo(self) -> None: pass
def bar(self) -> None: pass
class D(C):
# Error: Method "foo" is not using @override but is
# overriding a method
def foo(self) -> None:
...
@override
def bar(self) -> None: # OK
...
</pre>
<p>You can enable the error code via <tt>--enable-error-code=explicit-override</tt> on the mypy command line or <tt>enable_error_code = explicit-override</tt> in the mypy config file.
<p>The <tt>override</tt> decorator will be available in <tt>typing</tt> in Python 3.12, but you can also use the backport from a recent version of <tt>typing_extensions</tt> on all supported Python versions.
<p>This feature was contributed by Marc Mueller(PR <a href="https://github.com/python/mypy/pull/15512">15512</a>).
<h2>More Flexible TypedDict Creation and Update</h2>
<p>Mypy was previously overly strict when type checking TypedDict creation and update operations. Though these checks were often technically correct, they sometimes triggered for apparently valid code. These checks have now been relaxed by default. You can enable stricter checking by using the new <tt>--extra-checks</tt> flag.
<p>Construction using the <tt>**</tt> syntax is now more flexible:
<pre>
from typing import TypedDict
class A(TypedDict):
foo: int
bar: int
class B(TypedDict):
foo: int
a: A = {"foo": 1, "bar": 2}
b: B = {"foo": 3}
a2: A = { **a, **b} # OK (previously an error)
</pre>
<p>You can also call <tt>update()</tt> with a TypedDict argument that contains a subset of the keys in the updated TypedDict:
<pre>
a.update(b) # OK (previously an error)
</pre>
<p>This feature was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/15425">15425</a>).
<h2>Deprecated Flag: <tt>--strict-concatenate</tt></h2>
<p>The behavior of <tt>--strict-concatenate</tt> is now included in the new <tt>--extra-checks</tt> flag, and the old flag is deprecated.
<h2>Optionally Show Links to Error Code Documentation</h2>
<p>If you use <tt>--show-error-code-links</tt>, mypy will add documentation links to (many) reported errors. The links are not shown for error messages that are sufficiently obvious, and they are shown once per error code only.
<p>Example output:
<pre>
a.py:1: error: Need type annotation for "foo" (hint: "x: List[<type>] = ...") [var-annotated]
a.py:1: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-var-annotated for more info
</pre>
<p>This was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/15449">15449</a>).
<h2>Consistently Avoid Type Checking Unreachable Code</h2>
<p>If a module top level has unreachable code, mypy won’t type check the unreachable statements. This is consistent with how functions behave. The behavior of <tt>--warn-unreachable</tt> is also more consistent now.
<p>This was contributed by Ilya Priven (PR <a href="https://github.com/python/mypy/pull/15386">15386</a>).
<h2>Experimental Improved Type Inference for Generic Functions</h2>
<p>You can use <tt>--new-type-inference</tt> to opt into an experimental new type inference algorithm. It fixes issues when calling a generic functions with an argument that is also a generic function, in particular. This current implementation is still incomplete, but we encourage trying it out and reporting bugs if you encounter regressions. We are planning to enable the new algorithm by default in a future mypy release.
<p>This feature was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/15287">15287</a>).
<h2>Partial Support for Python 3.12</h2>
<p>Mypy and mypyc now support running on recent Python 3.12 development versions. Not all new Python 3.12 features are supported, and we don’t ship compiled wheels for Python 3.12 yet.
<ul>
<li>Fix <tt>ast</tt> warnings for Python 3.12 (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/15558">15558</a>)
<li>mypyc: Fix multiple inheritance with a protocol on Python 3.12 (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/15572">15572</a>)
<li>mypyc: Fix self-compilation on Python 3.12 (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/15582">15582</a>)
<li>mypyc: Fix 3.12 issue with pickling of instances with <tt>__dict__</tt> (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/15574">15574</a>)
<li>mypyc: Fix <tt>i16</tt> on Python 3.12 (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/15510">15510</a>)
<li>mypyc: Fix <tt>int</tt> operations on Python 3.12 (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/15470">15470</a>)
<li>mypyc: Fix generators on Python 3.12 (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/15472">15472</a>)
<li>mypyc: Fix classes with <tt>__dict__</tt> on 3.12 (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/15471">15471</a>)
<li>mypyc: Fix coroutines on Python 3.12 (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/15469">15469</a>)
<li>mypyc: Don't use <tt>_PyErr_ChainExceptions</tt> on 3.12, since it's deprecated (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/15468">15468</a>)
<li>mypyc: Add Python 3.12 feature macro (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/15465">15465</a>)
</ul>
<h2>Improvements to Dataclasses</h2>
<ul>
<li>Improve signature of <tt>dataclasses.replace</tt> (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/14849">14849</a>)
<li>Fix dataclass/protocol crash on joining types (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/15629">15629</a>)
<li>Fix strict optional handling in dataclasses (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15571">15571</a>)
<li>Support optional types for custom dataclass descriptors (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/15628">15628</a>)
<li>Add <tt>__slots__</tt> attribute to dataclasses (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/15649">15649</a>)
<li>Support better <tt>__post_init__</tt> method signature for <tt>dataclasses</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/15503">15503</a>)
</ul>
<h2>Mypyc Improvements</h2>
<ul>
<li>Support unsigned 8-bit native integer type: <tt>mypy_extensions.</tt><tt>u8</tt> (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/15564">15564</a>)
<li>Support signed 16-bit native integer type: <tt>mypy_extensions.</tt><tt>i16</tt> (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/15464">15464</a>)
<li>Define <tt>mypy_extensions.i16</tt> in stubs (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/15562">15562</a>)
<li>Document more unsupported features and update supported features (Richard Si, PR <a href="https://github.com/python/mypy/pull/15524">15524</a>)
<li>Fix final NamedTuple classes (Richard Si, PR <a href="https://github.com/python/mypy/pull/15513">15513</a>)
<li>Use C99 compound literals for undefined tuple values (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/15453">15453</a>)
<li>Don't explicitly assign <tt>NULL</tt> values in setup functions (Logan Hunt, PR <a href="https://github.com/python/mypy/pull/15379">15379</a>)
</ul>
<h2>Stubgen Improvements</h2>
<ul>
<li>Teach <tt>stubgen</tt> to work with <tt>complex</tt> and unary expressions (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/15661">15661</a>)
<li>Support <tt>ParamSpec</tt> and <tt>TypeVarTuple</tt> (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/15626">15626</a>)
<li>Fix crash on non-str docstring (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/15623">15623</a>)
</ul>
<h2>Documentation Updates</h2>
<ul>
<li>Add documentation for additional error codes (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15539">15539</a>)
<li>Improve documentation of type narrowing (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/15652">15652</a>)
<li>Small improvements to protocol documentation (Shantanu, PR <a href="https://github.com/python/mypy/pull/15460">15460</a>)
<li>Remove confusing instance variable example in cheat sheet (Adel Atallah, PR <a href="https://github.com/python/mypy/pull/15441">15441</a>)
</ul>
<h2>Other Notable Fixes and Improvements</h2>
<ul>
<li>Constant fold additional unary and binary expressions (Richard Si, PR <a href="https://github.com/python/mypy/pull/15202">15202</a>)
<li>Exclude the same special attributes from Protocol as CPython (Kyle Benesch, PR <a href="https://github.com/python/mypy/pull/15490">15490</a>)
<li>Change the default value of the <tt>slots</tt> argument of <tt>attrs.define</tt> to True, to match runtime behavior (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/15642">15642</a>)
<li>Fix type of class attribute if attribute is defined in both class and metaclass (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/14988">14988</a>)
<li>Handle <tt>type</tt> the same as <tt>typing.Type</tt> in the first argument of classmethods (Erik Kemperman, PR <a href="https://github.com/python/mypy/pull/15297">15297</a>)
<li>Fix <tt>--find-occurrences</tt> flag (Shantanu, PR <a href="https://github.com/python/mypy/pull/15528">15528</a>)
<li>Fix error location for class patterns (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/15506">15506</a>)
<li>Fix re-added file with errors in mypy daemon (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15440">15440</a>)
<li>Fix <tt>dmypy run</tt> on Windows (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15429">15429</a>)
<li>Fix abstract and non-abstract variant error for property deleter (Shantanu, PR <a href="https://github.com/python/mypy/pull/15395">15395</a>)
<li>Remove special casing for "cannot" in error messages (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/15428">15428</a>)
<li>Add runtime <tt>__slots__</tt> attribute to <tt>attrs</tt> classes (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/15651">15651</a>)
<li>Add <tt>get_expression_type</tt> to <tt>CheckerPluginInterface</tt> (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/15369">15369</a>)
<li>Remove parameters that no longer exist from <tt>NamedTuple._make()</tt> (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/15578">15578</a>)
<li>Allow using <tt>typing.Self</tt> in <tt>__new__</tt> with an explicit <tt>@</tt><tt>staticmethod</tt> decorator (Erik Kemperman, PR <a href="https://github.com/python/mypy/pull/15353">15353</a>)
<li>Fix self types in subclass methods without Self annotation (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15541">15541</a>)
<li>Check for abstract class objects in tuples (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/15366">15366</a>)
</ul>
<h2>Typeshed Updates</h2>
<p>Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see <a href="https://github.com/python/typeshed/commits/main?after=fc7d4722eaa54803926cee5730e1f784979c0531+0&branch=main&path=stdlib">git log</a> for full list of typeshed changes.
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<ul>
<li>Adel Atallah
<li>Alex Waygood
<li>Ali Hamdan
<li>Erik Kemperman
<li>Federico Padua
<li>Ilya Priven
<li>Ivan Levkivskyi
<li>Jelle Zijlstra
<li>Jared Hance
<li>Jukka Lehtosalo
<li>Kyle Benesch
<li>Logan Hunt
<li>Marc Mueller
<li>Nikita Sobolev
<li>Richard Si
<li>Shantanu
<li>Stavros Ntentos
<li>Valentin Stanciu
</ul>
</body>
</html>Unknownnoreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-89590591080671289852023-06-20T09:08:00.004-07:002023-06-20T09:11:49.913-07:00Mypy 1.4.0 Released<p>
</p><div style="text-align: left;">We’ve just uploaded mypy 1.4 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type checker for Python. This release includes new features, performance improvements and bug fixes. You can install it as follows:
</div><pre> python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
</p><h2>The Override Decorator</h2>
<p>Mypy can now ensure that when renaming a method, overrides are also renamed. You can explicitly mark a method as overriding a base class method by using the <tt>@typing.override</tt> decorator (<a href="https://peps.python.org/pep-0698/">PEP 698</a>). If the method is then renamed in the base class while the method override is not, mypy will generate an error. The decorator will be available in <tt>typing</tt> in Python 3.12, but you can also use the backport from a recent version of <tt>typing_extensions</tt> on all supported Python versions.
</p><p>This feature was contributed byThomas M Kehrenberg (PR <a href="https://github.com/python/mypy/pull/14609">14609</a>).
</p><h2>Propagating Type Narrowing to Nested Functions</h2>
<p>Previously, type narrowing was not propagated to nested functions because it would not be sound if the narrowed variable changed between the definition of the nested function and the call site. Mypy will now propagate the narrowed type if the variable is not assigned to after the definition of the nested function:
</p><pre> def outer(x: str | None = None) -> None:
if x is None:
x = calculate_default()
reveal_type(x) # "str" (narrowed)
def nested() -> None:
reveal_type(x) # Now "str" (used to be "str | None")
nested()
</pre>
<p>This may generate some new errors because asserts that were previously necessary may become tautological or no-ops.
</p><p>This was contributed by Jukka Lehtosalo (PR <a href="https://github.com/python/mypy/pull/15133">15133</a>).
</p><h2>Narrowing Enum Values Using “==”</h2>
<p>Mypy now allows narrowing enum types using the <tt>==</tt> operator. Previously this was only supported when using the <tt>is</tt> operator. This makes exhaustiveness checking with enum types more usable, as the requirement to use the <tt>is</tt> operator was not very intuitive. In this example mypy can detect that the developer forgot to handle the value <tt>MyEnum.C</tt> in <tt>example</tt>
</p><pre> from enum import Enum
class MyEnum(Enum):
A = 0
B = 1
C = 2
def example(e: MyEnum) -> str: # Error: Missing return statement
if e == MyEnum.A:
return 'x'
elif e == MyEnum.B:
return 'y'
</pre>
<p>Adding an extra elif case resolves the error:
</p><pre> ...
def example(e: MyEnum) -> str: # No error -- all values covered
if e == MyEnum.A:
return 'x'
elif e == MyEnum.B:
return 'y'
elif e == MyEnum.C:
return 'z'
</pre>
<p>This change can cause false positives in test cases that have assert statements like <tt>assert o.x == SomeEnum.X</tt> when using <tt>--strict-equality</tt>. Example:
</p><pre> # mypy: strict-equality
from enum import Enum
class MyEnum(Enum):
A = 0
B = 1
class C:
x: MyEnum
...
def test_something() -> None:
c = C(...)
assert c.x == MyEnum.A
c.do_something_that_changes_x()
assert c.x == MyEnum.B # Error: Non-overlapping equality check
</pre>
<p>These errors can be ignored using <tt># type: ignore[comparison-overlap]</tt>, or you can perform the assertion using a temporary variable as a workaround:
</p><pre> ...
def test_something() -> None:
...
x = c.x
assert x == MyEnum.A # Does not narrow c.x
c.do_something_that_changes_x()
x = c.x
assert x == MyEnum.B # OK
</pre>
<p>This feature was contributed by Shantanu (PR <a href="https://github.com/python/mypy/pull/11521">11521</a>).
</p><h2>Performance Improvements</h2>
<ul><li>Speed up simplification of large union types and also fix a recursive tuple crash (Shantanu, PR <a href="https://github.com/python/mypy/pull/15128">15128</a>)
</li><li>Speed up union subtyping (Shantanu, PR <a href="https://github.com/python/mypy/pull/15104">15104</a>)
</li><li>Don't type check most function bodies when type checking third-party library code, or generally when ignoring errors (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14150">14150</a>)
</li></ul>
<h2>Improvements to Plugins</h2>
<ul><li><tt>attrs.evolve</tt>: Support generics and unions (Ilya Konstantinov, PR <a href="https://github.com/python/mypy/pull/15050">15050</a>)
</li><li>Fix <tt>ctypes</tt> plugin (Alex Waygood)
</li></ul>
<h2>Fixes to Crashes</h2>
<ul><li>Fix a crash when function-scope recursive alias appears as upper bound (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15159">15159</a>)
</li><li>Fix crash on <tt>follow_imports_for_stubs</tt> (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15407">15407</a>)
</li><li>Fix stubtest crash in explicit init subclass (Shantanu, PR <a href="https://github.com/python/mypy/pull/15399">15399</a>)
</li><li>Fix crash when indexing TypedDict with empty key (Shantanu, PR <a href="https://github.com/python/mypy/pull/15392">15392</a>)
</li><li>Fix crash on NamedTuple as attribute (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15404">15404</a>)
</li><li>Correctly track loop depth for nested functions/classes (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15403">15403</a>)
</li><li>Fix crash on joins with recursive tuples (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15402">15402</a>)
</li><li>Fix crash with custom ErrorCode subclasses (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/15327">15327</a>)
</li><li>Fix crash in dataclass protocol with self attribute assignment (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15157">15157</a>)
</li><li>Fix crash on lambda in generic context with generic method in body (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15155">15155</a>)
</li><li>Fix recursive type alias crash in make_simplified_union (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15216">15216</a>)
</li></ul>
<h2>Improvements to Error Messages</h2>
<ul><li>Use lower-case built-in collection types such as <tt>list[…]</tt> instead of <tt>List[…]</tt> in errors when targeting Python 3.9+ (Max Murin, PR <a href="https://github.com/python/mypy/pull/15070">15070</a>)
</li><li>Use <tt>X | Y</tt> union syntax in error messages when targeting Python 3.10+ (Omar Silva, PR <a href="https://github.com/python/mypy/pull/15102">15102</a>)
</li><li>Use <tt>type</tt> instead of <tt>Type</tt> in errors when targeting Python 3.9+ (Rohit Sanjay, PR <a href="https://github.com/python/mypy/pull/15139">15139</a>)
</li><li>Do not show <tt>unused-ignore</tt> errors in unreachable code, and make it a real error code (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15164">15164</a>)
</li><li>Don’t limit the number of errors shown by default (Rohit Sanjay, PR <a href="https://github.com/python/mypy/pull/15138">15138</a>)
</li><li>Improver message for truthy functions (madt2709, PR <a href="https://github.com/python/mypy/pull/15193">15193</a>)
</li><li>Output distinct types when type names are ambiguous (teresa0605, PR <a href="https://github.com/python/mypy/pull/15184">15184</a>)
</li><li>Update message about invalid exception type in try (AJ Rasmussen, PR <a href="https://github.com/python/mypy/pull/15131">15131</a>)
</li><li>Add explanation if argument type is incompatible because of an unsupported <tt>numbers</tt> type (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/15137">15137</a>)
</li><li>Add more detail to 'signature incompatible with supertype' messages for non-callables (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/15263">15263</a>)
</li></ul>
<h2>Documentation Updates</h2>
<ul><li>Add <tt>--local-partial-types</tt> note to dmypy docs (Alan Du, PR <a href="https://github.com/python/mypy/pull/15259">15259</a>)
</li><li>Update getting started docs for mypyc for Windows (Valentin Stanciu, PR <a href="https://github.com/python/mypy/pull/15233">15233</a>)
</li><li>Clarify usage of callables regarding type object in docs (Viicos, PR <a href="https://github.com/python/mypy/pull/15079">15079</a>)
</li><li>Clarify difference between <tt>disallow_untyped_defs</tt> and <tt>disallow_incomplete_defs</tt> (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/15247">15247</a>)
</li><li>Use <tt>attrs</tt> and <tt>@attrs.define</tt> in documentation and tests (Ilya Priven, PR <a href="https://github.com/python/mypy/pull/15152">15152</a>)
</li></ul>
<h2>Mypyc Improvements</h2>
<ul><li>Fix unexpected <tt>TypeError</tt> for certain variables with an inferred optional type (Richard Si, PR <a href="https://github.com/python/mypy/pull/15206">15206</a>)
</li><li>Inline math literals (Logan Hunt, PR <a href="https://github.com/python/mypy/pull/15324">15324</a>)
</li><li>Support unpacking mappings in dict display (Richard Si, PR <a href="https://github.com/python/mypy/pull/15203">15203</a>)
</li></ul>
<h2>Changes to Stubgen</h2>
<ul><li>Do not remove Generic from base classes (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/15316">15316</a>)
</li><li>Support <tt>yield from</tt> statements (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/15271">15271</a>)
</li><li>Fix missing <tt>total</tt> from TypedDict class (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/15208">15208</a>)
</li><li>Fix call-based namedtuple omitted from class bases (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/14680">14680</a>)
</li><li>Support TypedDict alternative syntax (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/14682">14682</a>)
</li><li>Make stubgen respect MYPY_CACHE_DIR (Henrik Bäärnhielm, PR <a href="https://github.com/python/mypy/pull/14722">14722</a>)
</li><li>Fixes and simplifications (Ali Hamdan, PR <a href="https://github.com/python/mypy/pull/15232">15232</a>)
</li></ul>
<h2>Other Notable Fixes and Improvements</h2>
<ul><li>Fix nested async functions when using TypeVar value restriction (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14705">14705</a>)
</li><li>Always allow returning Any from lambda (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15413">15413</a>)
</li><li>Add foundation for TypeVar defaults (PEP 696) (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/14872">14872</a>)
</li><li>Update semantic analyzer for TypeVar defaults (PEP 696) (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/14873">14873</a>)
</li><li>Make dict expression inference more consistent (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/15174">15174</a>)
</li><li>Do not block on duplicate base classes (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/15367">15367</a>)
</li><li>Generate an error when both staticmethod and classmethod decorators are used (Juhi Chandalia, PR <a href="https://github.com/python/mypy/pull/15118">15118</a>)
</li><li>Fix <tt>assert_type</tt> behaviour with literals (Carl Karsten, PR <a href="https://github.com/python/mypy/pull/15123">15123</a>)
</li><li>Fix match subject ignoring redefinitions (Vincent Vanlaer, PR <a href="https://github.com/python/mypy/pull/15306">15306</a>)
</li><li>Support <tt>__all__.remove</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/15279">15279</a>)
</li></ul>
<h2>Typeshed Updates</h2>
<p>Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see <a href="https://github.com/python/typeshed/commits/main?after=877e06ad1cfd9fd9967c0b0340a86d0c23ea89ce+0&branch=main&path=stdlib">git log</a> for full list of typeshed changes.
</p><h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
</p><ul><li>Adrian Garcia Badaracco
</li><li>AJ Rasmussen
</li><li>Alan Du
</li><li>Alex Waygood
</li><li>Ali Hamdan
</li><li>Carl Karsten
</li><li>dosisod
</li><li>Ethan Smith
</li><li>Gregory Santosa
</li><li>Heather White
</li><li>Henrik Bäärnhielm
</li><li>Ilya Konstantinov
</li><li>Ilya Priven
</li><li>Ivan Levkivskyi
</li><li>Juhi Chandalia
</li><li>Jukka Lehtosalo
</li><li>Logan Hunt
</li><li>madt2709
</li><li>Marc Mueller
</li><li>Max Murin
</li><li>Nikita Sobolev
</li><li>Omar Silva
</li><li>Özgür
</li><li>Richard Si
</li><li>Rohit Sanjay
</li><li>Shantanu
</li><li>teresa0605
</li><li>Thomas M Kehrenberg
</li><li>Tin Tvrtković
</li><li>Tushar Sadhwani
</li><li>Valentin Stanciu
</li><li>Viicos
</li><li>Vincent Vanlaer
</li><li>Wesley Collin Wright
</li><li>William Santosa
</li><li>yaegassy
</li></ul>
<p>I’d also like to thank my employer, Dropbox, for supporting mypy development.
</p>Jared Hancehttp://www.blogger.com/profile/13451114101069297635noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-23420216417923859632023-05-10T04:04:00.003-07:002023-05-10T09:10:38.830-07:00Mypy 1.3 Released<html>
<meta charset="utf-8" />
<body>
We’ve just uploaded mypy 1.3 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type checker for Python. This release includes new features, performance improvements and bug fixes. You can install it as follows:
<pre>
python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Performance Improvements</h2>
<ul>
<li>Improve performance of union subtyping (Shantanu, PR <a href="https://github.com/python/mypy/pull/15104">15104</a>)
<li>Add negative subtype caches (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14884">14884</a>)
</ul>
<h2>Stub Tooling Improvements</h2>
<ul>
<li>Stubtest: Check that the stub is abstract if the runtime is, even when the stub is an overloaded method (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/14955">14955</a>)
<li>Stubtest: Verify stub methods or properties are decorated with <tt>@final</tt> if they are decorated with <tt>@final</tt> at runtime (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/14951">14951</a>)
<li>Stubtest: Fix stubtest false positives with TypedDicts at runtime (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/14984">14984</a>)
<li>Stubgen: Support <tt>@functools.cached_property</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/14981">14981</a>)
<li>Improvements to stubgenc (Chad Dombrova, PR <a href="https://github.com/python/mypy/pull/14564">14564</a>)
</ul>
<h2>Improvements to attrs</h2>
<ul>
<li>Add support for converters with TypeVars on generic attrs classes (Chad Dombrova, PR <a href="https://github.com/python/mypy/pull/14908">14908</a>)
<li>Fix <tt>attrs.evolve</tt> on bound TypeVar (Ilya Konstantinov, PR <a href="https://github.com/python/mypy/pull/15022">15022</a>)
</ul>
<h2>Documentation Updates</h2>
<ul>
<li>Improve async documentation (Shantanu, PR <a href="https://github.com/python/mypy/pull/14973">14973</a>)
<li>Improvements to cheat sheet (Shantanu, PR <a href="https://github.com/python/mypy/pull/14972">14972</a>)
<li>Add documentation for bytes formatting error code (Shantanu, PR <a href="https://github.com/python/mypy/pull/14971">14971</a>)
<li>Convert insecure links to use HTTPS (Marti Raudsepp, PR <a href="https://github.com/python/mypy/pull/14974">14974</a>)
<li>Also mention overloads in async iterator documentation (Shantanu, PR <a href="https://github.com/python/mypy/pull/14998">14998</a>)
<li>stubtest: Improve allowlist documentation (Shantanu, PR <a href="https://github.com/python/mypy/pull/15008">15008</a>)
<li>Clarify "Using types... but not at runtime" (Jon Shea, PR <a href="https://github.com/python/mypy/pull/15029">15029</a>)
<li>Fix alignment of cheat sheet example (Ondřej Cvacho, PR <a href="https://github.com/python/mypy/pull/15039">15039</a>)
<li>Fix error for callback protocol matching against callable type object (Shantanu, PR <a href="https://github.com/python/mypy/pull/15042">15042</a>)
</ul>
<h2>Error Reporting Improvements</h2>
<ul>
<li>Improve bytes formatting error (Shantanu, PR <a href="https://github.com/python/mypy/pull/14959">14959</a>)
</ul>
<h2>Mypyc Improvements</h2>
<ul>
<li>Fix unions of bools and ints (Tomer Chachamu, PR <a href="https://github.com/python/mypy/pull/15066">15066</a>)
</ul>
<h2>Other Fixes and Improvements</h2>
<ul>
<li>Fix narrowing union types that include Self with <tt>isinstance</tt> (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/14923">14923</a>)
<li>Allow objects matching <tt>SupportsKeysAndGetItem</tt> to be unpacked (Bryan Forbes, PR <a href="https://github.com/python/mypy/pull/14990">14990</a>)
<li>Check type guard validity for staticmethods (EXPLOSION, PR <a href="https://github.com/python/mypy/pull/14953">14953</a>)
<li>Fix <tt>sys.platform</tt> when cross-compiling with emscripten (Ethan Smith, PR <a href="https://github.com/python/mypy/pull/14888">14888</a>)
</ul>
<h2>Typeshed Updates</h2>
<p>Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see <a href="https://github.com/python/typeshed/commits/main?after=b0ed50e9392a23e52445b630a808153e0e256976+0&branch=main&path=stdlib">git log</a> for full list of typeshed changes.
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<ul>
<li>Alex Waygood
<li>Amin Alaee
<li>Bryan Forbes
<li>Chad Dombrova
<li>Charlie Denton
<li>Christoph Tyralla
<li>dosisod
<li>Ethan Smith
<li>EXPLOSION
<li>Ilya Konstantinov
<li>Ivan Levkivskyi
<li>Jon Shea
<li>Jukka Lehtosalo
<li>KotlinIsland
<li>Marti Raudsepp
<li>Nikita Sobolev
<li>Ondřej Cvacho
<li>Shantanu
<li>sobolevn
<li>Tomer Chachamu
<li>Yaroslav Halchenko
</ul></body>
</html>Unknownnoreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-19698374216002334862023-04-06T08:36:00.000-07:002023-04-06T08:36:53.300-07:00Mypy 1.2 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 1.2 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type checker for Python. This release includes new features, performance improvements and bug fixes. You can install it as follows:
<pre>
python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Improvements to Dataclass Transforms</h2>
<ul>
<li>Support implicit default for "init" parameter in field specifiers (Wesley Collin Wright and Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/15010">15010</a>)
<li>Support descriptors in dataclass transform (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/15006">15006</a>)
<li>Fix frozen_default in incremental mode (Wesley Collin Wright)
<li>Fix frozen behavior for base classes with direct metaclasses (Wesley Collin Wright, PR <a href="https://github.com/python/mypy/pull/14878">14878</a>)
</ul>
<h2>Mypyc: Native Floats</h2>
<p>Mypyc now uses a native, unboxed representation for values of type <tt>float</tt>. Previously these were heap-allocated Python objects. Native floats are faster and use less memory. Code that uses floating-point operations heavily can be several times faster when using native floats.
<p>Various float operations and <tt>math</tt> functions also now have optimized implementations. Refer to the <a href="https://mypyc.readthedocs.io/en/latest/float_operations.html">documentation</a> for a full list.
<p>This can change the behavior of existing code that uses subclasses of <tt>float</tt>. When assigning an instance of a subclass of <tt>float</tt> to a variable with the <tt>float</tt> type, it gets implicitly converted to a <tt>float</tt> instance when compiled:
<pre>
from lib import MyFloat # MyFloat ia a subclass of "float"
</pre>
<pre>
def example() -> None:
x = MyFloat(1.5)
y: float = x # Implicit conversion from MyFloat to float
print(type(y)) # float, not MyFloat
</pre>
<p>Previously, implicit conversions were applied to <tt>int</tt> subclasses but not <tt>float</tt> subclasses.
<p>Also, <tt>int</tt> values can no longer be assigned to a variable with type <tt>float</tt> in compiled code, since these types now have incompatible representations. An explicit conversion is required:
<pre>
def example(n: int) -> None:
a: float = 1 # Error: cannot assign "int" to "float"
b: float = 1.0 # OK
c: float = n # Error
d: float = float(n) # OK
</pre>
<p>This restriction only applies to assignments, since they could otherwise narrow down the type of a variable from <tt>float</tt> to <tt>int</tt>. <tt>int</tt> values can still be implicitly converted to <tt>float</tt> when passed as arguments to functions that expect <tt>float</tt> values.
<p>Note that mypyc still doesn’t support arrays of unboxed float values. Using <tt>list[float]</tt> involves heap-allocated <tt>float</tt> objects, since <tt>list</tt> can only store boxed values. Support for efficient floating point arrays is one of the next major planned mypyc features.
<p>Related changes:
<ul>
<li>Use a native unboxed representation for floats (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14880">14880</a>)
<li>Document native floats and integers (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14927">14927</a>)
<li>Fixes to float to int conversion (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14936">14936</a>)
</ul>
<h2>Mypyc: Native Integers</h2>
<p>Mypyc now supports signed 32-bit and 64-bit integer types in addition to the arbitrary-precision <tt>int</tt> type. You can use the types <tt>mypy_extensions.i32</tt> and <tt>mypy_extensions.i64</tt> to speed up code that uses integer operations heavily.
<p>Simple example:
<pre>
from mypy_extensions import i64
</pre>
<pre>
def inc(x: i64) -> i64:
return x + 1
</pre>
<p>Refer to the <a href="https://mypyc.readthedocs.io/en/latest/using_type_annotations.html#native-integer-types">documentation</a> for more information. This feature was contributed by Jukka Lehtosalo.
<h2>Other Mypyc Fixes and Improvements</h2>
<ul>
<li>Support iterating over a TypedDict (Richard Si, PR <a href="https://github.com/python/mypy/pull/14747">14747</a>)
<li>Faster coercions between different tuple types (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14899">14899</a>)
<li>Faster calls via type aliases (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14784">14784</a>)
<li>Faster classmethod calls via <tt>cls</tt> (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14789">14789</a>)
</ul>
<h2>Fixes to Crashes</h2>
<ul>
<li>Fix crash on class-level import in protocol definition (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14926">14926</a>)
<li>Fix crash on single item union of alias (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14876">14876</a>)
<li>Fix crash on ParamSpec in incremental mode (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14885">14885</a>)
</ul>
<h2>Documentation Updates</h2>
<ul>
<li>Update adopting <tt>--strict</tt> documentation for 1.0 (Shantanu, PR <a href="https://github.com/python/mypy/pull/14865">14865</a>)
<li>Some minor documentation tweaks (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14847">14847</a>)
<li>Improve documentation of top level <tt>mypy: disable-error-code</tt> comment (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/14810">14810</a>)
</ul>
<h2>Error Reporting Improvements</h2>
<ul>
<li>Add error code to <tt>typing_extensions</tt> suggestion (Shantanu, PR <a href="https://github.com/python/mypy/pull/14881">14881</a>)
<li>Add a separate error code for top-level <tt>await</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/14801">14801</a>)
<li>Don’t suggest two obsolete stub packages (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/14842">14842</a>)
<li>Add suggestions for <tt>pandas-stubs</tt> and <tt>lxml-stubs</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/14737">14737</a>)
</ul>
<h2>Other Fixes and Improvements</h2>
<ul>
<li>Multiple inheritance considers callable objects as subtypes of functions (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/14855">14855</a>)
<li>stubtest: Respect <tt>@final</tt> runtime decorator and enforce it in stubs (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/14922">14922</a>)
<li>Fix false positives related to <tt>type[<type-var>]</tt> (sterliakov, PR <a href="https://github.com/python/mypy/pull/14756">14756</a>)
<li>Fix duplication of ParamSpec prefixes and properly substitute ParamSpecs (EXPLOSION, PR <a href="https://github.com/python/mypy/pull/14677">14677</a>)
<li>Fix line number if <tt>__iter__</tt> is incorrectly reported as missing (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14893">14893</a>)
<li>Fix incompatible overrides of overloaded generics with self types (Shantanu, PR <a href="https://github.com/python/mypy/pull/14882">14882</a>)
<li>Allow <tt>SupportsIndex</tt> in slice expressions (Shantanu, PR <a href="https://github.com/python/mypy/pull/14738">14738</a>)
<li>Support <tt>if</tt> statements in bodies of dataclasses and classes that use <tt>dataclass_transform</tt> (Jacek Chałupka, PR <a href="https://github.com/python/mypy/pull/14854">14854</a>)
<li>Allow iterable class objects to be unpacked (including enums) (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/14827">14827</a>)
<li>Fix narrowing for walrus expressions used in match statements (Shantanu, PR <a href="https://github.com/python/mypy/pull/14844">14844</a>)
<li>Add signature for <tt>attr.evolve</tt> (Ilya Konstantinov, PR <a href="https://github.com/python/mypy/pull/14526">14526</a>)
<li>Fix <tt>Any</tt> inference when unpacking iterators that don't directly inherit from <tt>typing.Iterator</tt> (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/14821">14821</a>)
<li>Fix unpack with overloaded <tt>__iter__</tt> method (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/14817">14817</a>)
<li>Reduce size of JSON data in mypy cache (dosisod, PR <a href="https://github.com/python/mypy/pull/14808">14808</a>)
<li>Improve “used before definition” checks when a local definition has the same name as a global definition (Stas Ilinskiy, PR <a href="https://github.com/python/mypy/pull/14517">14517</a>)
<li>Honor <tt>NoReturn</tt> as <tt>__setitem__</tt> return type to mark unreachable code (sterliakov, PR <a href="https://github.com/python/mypy/pull/12572">12572</a>)
</ul>
<h2>Typeshed Updates</h2>
<p>Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see <a href="https://github.com/python/typeshed/commits/main?after=a544b75320e97424d2d927605316383c755cdac0+0&branch=main&path=stdlib">git log</a> for full list of typeshed changes.
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<ul>
<li>Alex Waygood
<li>Avasam
<li>Christoph Tyralla
<li>dosisod
<li>EXPLOSION
<li>Ilya Konstantinov
<li>Ivan Levkivskyi
<li>Jacek Chałupka
<li>Jelle Zijlstra
<li>Jukka Lehtosalo
<li>Marc Mueller
<li>Max Murin
<li>Nikita Sobolev
<li>Richard Si
<li>Shantanu
<li>Stas Ilinskiy
<li>sterliakov
<li>Wesley Collin Wright
</ul></body>
</html>
Jukka Lehtosalohttp://www.blogger.com/profile/00122775610277203624noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-2215681972177179642023-03-06T18:31:00.000-08:002023-03-06T18:31:04.798-08:00Mypy 1.1.1 Released<html>
<meta charset="utf-8" />
<body>
We’ve just uploaded mypy 1.1.1 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type checker for Python. This release includes new features, performance improvements and bug fixes. You can install it as follows:
<pre>
python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Support for <tt>dataclass_transform</tt></h2>
<p>This release adds full support for the <tt>dataclass_transform</tt> decorator defined in <a href="https://peps.python.org/pep-0681/#decorator-function-example">PEP 681</a>. This allows decorators, base classes, and metaclasses that generate a <tt>__init__</tt> method or other methods based on the properties of that class (similar to dataclasses) to have those methods recognized by mypy.
<p>This was contributed by Wesley Collin Wright.
<h2>Dedicated Error Code for Method Assignments</h2>
<p>Mypy can’t safely check all assignments to methods (a form of monkey patching), so mypy generates an error by default. To make it easier to ignore this error, mypy now uses the new error code <tt>method-assign</tt> for this. By disabling this error code in a file or globally, mypy will no longer complain about assignments to methods if the signatures are compatible.
<p>Mypy also supports the old error code <tt>assignment</tt> for these assignments to prevent a backward compatibility break. More generally, we can use this mechanism in the future if we wish to split or rename another existing error code without causing backward compatibility issues.
<p>This was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/14570">14570</a>).
<h2>Fixes to Crashes</h2>
<ul>
<li>Fix a crash on walrus in comprehension at class scope (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14556">14556</a>)
<li>Fix crash related to value-constrained TypeVar (Shantanu, PR <a href="https://github.com/python/mypy/pull/14642">14642</a>)
</ul>
<h2>Fixes to Cache Corruption</h2>
<ul>
<li>Fix generic TypedDict/NamedTuple caching (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14675">14675</a>)
</ul>
<h2>Mypyc Fixes and Improvements</h2>
<ul>
<li>Raise "non-trait base must be first..." error less frequently (Richard Si, PR <a href="https://github.com/python/mypy/pull/14468">14468</a>)
<li>Generate faster code for bool comparisons and arithmetic (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14489">14489</a>)
<li>Optimize <tt>__(a)enter__</tt>/<tt>__(a)exit__</tt> for native classes (Jared Hance, PR <a href="https://github.com/python/mypy/pull/14530">14530</a>)
<li>Detect if attribute definition conflicts with base class/trait (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14535">14535</a>)
<li>Support <tt>__(r)divmod__</tt> dunders (Richard Si, PR <a href="https://github.com/python/mypy/pull/14613">14613</a>)
<li>Support <tt>__pow__</tt>, <tt>__rpow__</tt>, and <tt>__ipow__</tt> dunders (Richard Si, PR <a href="https://github.com/python/mypy/pull/14616">14616</a>)
<li>Fix crash on star unpacking to underscore (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14624">14624</a>)
<li>Fix iterating over a union of dicts (Richard Si, PR <a href="https://github.com/python/mypy/pull/14713">14713</a>)
</ul>
<h2>Fixes to Detecting Undefined Names (used-before-def)</h2>
<ul>
<li>Correctly handle walrus operator (Stas Ilinskiy, PR <a href="https://github.com/python/mypy/pull/14646">14646</a>)
<li>Handle walrus declaration in match subject correctly (Stas Ilinskiy, PR <a href="https://github.com/python/mypy/pull/14665">14665</a>)
</ul>
<h2>Stubgen Improvements</h2>
<p>Stubgen is a tool for automatically generating draft stubs for libraries.
<ul>
<li>Allow aliases below the top level (Chad Dombrova, PR <a href="https://github.com/python/mypy/pull/14388">14388</a>)
<li>Fix crash with PEP 604 union in type variable bound (Shantanu, PR <a href="https://github.com/python/mypy/pull/14557">14557</a>)
<li>Preserve PEP 604 unions in generated .pyi files (hamdanal, PR <a href="https://github.com/python/mypy/pull/14601">14601</a>)
</ul>
<h2>Stubtest Improvements</h2>
<p>Stubtest is a tool for testing that stubs conform to the implementations.
<ul>
<li>Update message format so that it’s easier to go to error location (Avasam, PR <a href="https://github.com/python/mypy/pull/14437">14437</a>)
<li>Handle name-mangling edge cases better (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/14596">14596</a>)
</ul>
<h2>Changes to Error Reporting and Messages</h2>
<ul>
<li>Add new TypedDict error code <tt>typeddict-unknown-key</tt> (JoaquimEsteves, PR <a href="https://github.com/python/mypy/pull/14225">14225</a>)
<li>Give arguments a more reasonable location in error messages (Max Murin, PR <a href="https://github.com/python/mypy/pull/14562">14562</a>)
<li>In error messages, quote just the module's name (Ilya Konstantinov, PR <a href="https://github.com/python/mypy/pull/14567">14567</a>)
<li>Improve misleading message about Enum() (Rodrigo Silva, PR <a href="https://github.com/python/mypy/pull/14590">14590</a>)
<li>Suggest importing from <tt>typing_extensions</tt> if definition is not in <tt>typing</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/14591">14591</a>)
<li>Consistently use <tt>type-abstract</tt> error code (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14619">14619</a>)
<li>Consistently use <tt>literal-required</tt> error code for TypedDicts (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14621">14621</a>)
<li>Adjust inconsistent dataclasses plugin error messages (Wesley Collin Wright, PR <a href="https://github.com/python/mypy/pull/14637">14637</a>)
<li>Consolidate literal bool argument error messages (Wesley Collin Wright, PR <a href="https://github.com/python/mypy/pull/14693">14693</a>)
</ul>
<h2>Other Fixes and Improvements</h2>
<ul>
<li>Check that type guards accept a positional argument (EXPLOSION, PR <a href="https://github.com/python/mypy/pull/14238">14238</a>)
<li>Fix bug with in operator used with a union of Container and Iterable (Max Murin, PR <a href="https://github.com/python/mypy/pull/14384">14384</a>)
<li>Support protocol inference for <tt>t</tt><tt>ype[T]</tt> via metaclass (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14554">14554</a>)
<li>Allow overlapping comparisons between bytes-like types (Shantanu, PR <a href="https://github.com/python/mypy/pull/14658">14658</a>)
<li>Fix mypy daemon documentation link in README (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14644">14644</a>)
</ul>
<h2>Typeshed Updates</h2>
<p>Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see <a href="https://github.com/python/typeshed/commits/main?after=5ebf892d0710a6e87925b8d138dfa597e7bb11cc+0&branch=main&path=stdlib">git log</a> for full list of typeshed changes.
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<ul>
<li>Alex Waygood
<li>Avasam
<li>Chad Dombrova
<li>dosisod
<li>EXPLOSION
<li>hamdanal
<li>Ilya Konstantinov
<li>Ivan Levkivskyi
<li>Jared Hance
<li>JoaquimEsteves
<li>Jukka Lehtosalo
<li>Marc Mueller
<li>Max Murin
<li>Michael Lee
<li>Michael R. Crusoe
<li>Richard Si
<li>Rodrigo Silva
<li>Shantanu
<li>Stas Ilinskiy
<li>Wesley Collin Wright
<li>Yilei "Dolee" Yang
<li>Yurii Karabas
</ul>
<p>We’d also like to thank our employer, Dropbox, for funding the mypy core team.</body>
</html>
Max Murinhttp://www.blogger.com/profile/07972579056463365303noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-59812700342087302682023-02-06T10:48:00.001-08:002023-02-06T12:10:43.929-08:00Mypy 1.0 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 1.0 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type checker for Python. This release includes new features, performance improvements and bug fixes. You can install it as follows:
<pre>
python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>New Release Versioning Scheme</h2>
<p>Now that mypy reached 1.0, we’ll switch to a new versioning scheme. Mypy version numbers will be of form x.y.z.
<p>Rules:
<ul>
<li>The major release number (x) is incremented if a feature release includes a significant backward incompatible change that affects a significant fraction of users.
<li>The minor release number (y) is incremented on each feature release. Minor releases include updated stdlib stubs from typeshed.
<li>The point release number (z) is incremented when there are fixes only.
</ul>
<p>Mypy doesn't use SemVer, since most minor releases have at least minor backward incompatible changes in typeshed, at the very least. Also, many type checking features find new legitimate issues in code. These are not considered backward incompatible changes, unless the number of new errors is very high.
<p>Any significant backward incompatible change must be announced in the blog post for the previous feature release, before making the change. The previous release must also provide a flag to explicitly enable or disable the new behavior (whenever practical), so that users will be able to prepare for the changes and report issues. We should keep the feature flag for at least a few releases after we've switched the default.
<p>See <a href="https://github.com/python/mypy/wiki/Release-Process">”Release Process” in the mypy wiki</a> for more details and for the most up-to-date version of the versioning scheme.
<h2>Performance Improvements</h2>
<p>Mypy 1.0 is up to 40% faster than mypy 0.991 when type checking the Dropbox internal codebase. We also set up a daily job to measure the performance of the most recent development version of mypy to make it easier to track changes in performance.
<p>Many optimizations contributed to this improvement:
<ul>
<li>Improve performance for errors on class with many attributes (Shantanu, PR <a href="https://github.com/python/mypy/pull/14379">14379</a>)
<li>Speed up make_simplified_union (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14370">14370</a>)
<li>Micro-optimize get_proper_type(s) (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14369">14369</a>)
<li>Micro-optimize flatten_nested_unions (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14368">14368</a>)
<li>Some semantic analyzer micro-optimizations (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14367">14367</a>)
<li>A few miscellaneous micro-optimizations (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14366">14366</a>)
<li>Optimization: Avoid a few uses of contextmanagers in semantic analyzer (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14360">14360</a>)
<li>Optimization: Enable always defined attributes in Type subclasses (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14356">14356</a>)
<li>Optimization: Remove expensive context manager in type analyzer (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14357">14357</a>)
<li>subtypes: fast path for Union/Union subtype check (Hugues, PR <a href="https://github.com/python/mypy/pull/14277">14277</a>)
<li>Micro-optimization: avoid Bogus[int] types that cause needless boxing (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14354">14354</a>)
<li>Avoid slow error message logic if errors not shown to user (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14336">14336</a>)
<li>Speed up the implementation of hasattr() checks (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14333">14333</a>)
<li>Avoid the use of a context manager in hot code path (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14331">14331</a>)
<li>Change various type queries into faster bool type queries (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14330">14330</a>)
<li>Speed up recursive type check (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14326">14326</a>)
<li>Optimize subtype checking by avoiding a nested function (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14325">14325</a>)
<li>Optimize type parameter checks in subtype checking (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14324">14324</a>)
<li>Speed up freshening type variables (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14323">14323</a>)
<li>Optimize implementation of TypedDict types for **kwds (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14316">14316</a>)
</ul>
<h2>Warn About Variables Used Before Definition</h2>
<p>Mypy will now generate an error if you use a variable before it’s defined. This feature is enabled by default. By default mypy reports an error when it infers that a variable is always undefined.
<pre>
y = x # E: Name "x" is used before definition [used-before-def]
x = 0
</pre>
<p>This feature was contributed by Stas Ilinskiy.
<h2>Detect Possibly Undefined Variables (Experimental)</h2>
<p>A new experimental <tt>possibly-undefined</tt> error code is now available that will detect variables that may be undefined:
<pre>
if b:
x = 0
print(x) # Error: Name "x" may be undefined [possibly-undefined]
</pre>
<p>The error code is disabled be default, since it can generate false positives.
<p>This feature was contributed by Stas Ilinskiy.
<h2>Support the “Self” Type</h2>
<p>There is now a simpler syntax for declaring <a href="https://mypy.readthedocs.io/en/stable/generics.html#generic-methods-and-generic-self">generic self types</a> introduced in <a href="https://peps.python.org/pep-0673/">PEP 673</a>: the <tt>Self</tt> type. You no longer have to define a type variable to use “self types”, and you can use them with attributes. Example from mypy documentation:
<pre>
from typing import Self
class Friend:
other: Self | None = None
@classmethod
def make_pair(cls) -> tuple[Self, Self]:
a, b = cls(), cls()
a.other = b
b.other = a
return a, b
class SuperFriend(Friend):
pass
# a and b have the inferred type "SuperFriend", not "Friend"
a, b = SuperFriend.make_pair()
</pre>
<p>The feature was introduced in Python 3.11. In earlier Python versions a backport of <tt>Self</tt> is available in <tt>typing_extensions</tt>.
<p>This was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/14041">14041</a>).
<h2>Support ParamSpec in Type Aliases</h2>
<tt>ParamSpec</tt> and <tt>Concatenate</tt> can now be used in type aliases. Example:
<pre>
from typing import ParamSpec, Callable
P = ParamSpec("P")
A = Callable[P, None]
def f(c: A[int, str]) -> None:
c(1, "x")
</pre>
<p>This feature was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/14159">14159</a>).
<h2>ParamSpec and Generic Self Types No Longer Experimental</h2>
<p>Support for ParamSpec (<a href="https://www.python.org/dev/peps/pep-0612/">PEP 612</a>) and generic self types are no longer considered experimental.
<h2>Miscellaneous New Features</h2>
<ul>
<li>Minimal, partial implementation of <tt>dataclass_transform</tt> (<a href="https://peps.python.org/pep-0681/">PEP 681</a>) (Wesley Collin Wright, PR <a href="https://github.com/python/mypy/pull/14523">14523</a>)
<li>Add basic support for <tt>typing_extensions.TypeVar</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/14313">14313</a>)
<li>Add <tt>--debug-serialize</tt> option (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/14155">14155</a>)
<li>Constant fold initializers of final variables (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14283">14283</a>)
<li>Enable Final instance attributes for attrs (Tin Tvrtković, PR <a href="https://github.com/python/mypy/pull/14232">14232</a>)
<li>Allow function arguments as base classes (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14135">14135</a>)
<li>Allow <tt>super()</tt> with mixin protocols (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14082">14082</a>)
<li>Add type inference for <tt>dict.keys</tt> membership (Matthew Hughes, PR <a href="https://github.com/python/mypy/pull/13372">13372</a>)
<li>Generate error for class attribute access if attribute is defined with <tt>__slots__</tt> (Harrison McCarty, PR <a href="https://github.com/python/mypy/pull/14125">14125</a>)
<li>Support additional attributes in callback protocols (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14084">14084</a>)
</ul>
<h2>Fixes to Crashes</h2>
<ul>
<li>Fix crash on prefixed ParamSpec with forward reference (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14569">14569</a>)
<li>Fix internal crash when resolving the same partial type twice (Shantanu, PR <a href="https://github.com/python/mypy/pull/14552">14552</a>)
<li>Fix crash in daemon mode on new import cycle (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14508">14508</a>)
<li>Fix crash in mypy daemon (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14497">14497</a>)
<li>Fix crash on <tt>Any</tt> metaclass in incremental mode (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14495">14495</a>)
<li>Fix crash in await inside comprehension outside function (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14486">14486</a>)
<li>Fix crash in Self type on forward reference in upper bound (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14206">14206</a>)
<li>Fix a crash when incorrect <tt>super()</tt> is used outside a method (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14208">14208</a>)
<li>Fix crash on overriding with frozen attrs (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14186">14186</a>)
<li>Fix incremental mode crash on generic function appearing in nested position (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14148">14148</a>)
<li>Fix daemon crash on malformed NamedTuple (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14119">14119</a>)
<li>Fix crash during ParamSpec inference (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14118">14118</a>)
<li>Fix crash on nested generic callable (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14093">14093</a>)
<li>Fix crashes with unpacking SyntaxError (Shantanu, PR <a href="https://github.com/python/mypy/pull/11499">11499</a>)
<li>Fix crash on partial type inference within a lambda (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14087">14087</a>)
<li>Fix crash with enums (Michael Lee, PR <a href="https://github.com/python/mypy/pull/14021">14021</a>)
<li>Fix crash with malformed TypedDicts and disllow-any-expr (Michael Lee, PR <a href="https://github.com/python/mypy/pull/13963">13963</a>)
</ul>
<h2>Error Reporting Improvements</h2>
<ul>
<li>More helpful error for missing self (Shantanu, PR <a href="https://github.com/python/mypy/pull/14386">14386</a>)
<li>Add error-code <tt>truthy-iterable</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/13762">13762</a>)
<li>Fix pluralization in error messages (KotlinIsland, PR <a href="https://github.com/python/mypy/pull/14411">14411</a>)
</ul>
<h2>Mypyc: Support Match Statement</h2>
<p>Mypyc can now compile Python 3.10 match statements.
<p>This was contributed by dosisod (PR <a href="https://github.com/python/mypy/pull/13953">13953</a>).
<h2>Other Mypyc Fixes and Improvements</h2>
<ul>
<li>Optimize <tt>int(</tt><tt>x</tt><tt>)</tt>/<tt>float(</tt><tt>x</tt><tt>)</tt>/<tt>complex(</tt><tt>x</tt><tt>)</tt> on instances of native classes (Richard Si, PR <a href="https://github.com/python/mypy/pull/14450">14450</a>)
<li>Always emit warnings (Richard Si, PR <a href="https://github.com/python/mypy/pull/14451">14451</a>)
<li>Faster bool and integer conversions (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14422">14422</a>)
<li>Support attributes that override properties (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14377">14377</a>)
<li>Precompute set literals for "in" operations and iteration (Richard Si, PR <a href="https://github.com/python/mypy/pull/14409">14409</a>)
<li>Don't load targets with forward references while setting up non-extension class <tt>__annotations__</tt> (Richard Si, PR <a href="https://github.com/python/mypy/pull/14401">14401</a>)
<li>Compile away NewType type calls (Richard Si, PR <a href="https://github.com/python/mypy/pull/14398">14398</a>)
<li>Improve error message for multiple inheritance (Joshua Bronson, PR <a href="https://github.com/python/mypy/pull/14344">14344</a>)
<li>Simplify union types (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14363">14363</a>)
<li>Fixes to union simplification (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14364">14364</a>)
<li>Fix for typeshed changes to Collection (Shantanu, PR <a href="https://github.com/python/mypy/pull/13994">13994</a>)
<li>Allow use of <tt>enum.Enum</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/13995">13995</a>)
<li>Fix compiling on Arch Linux (dosisod, PR <a href="https://github.com/python/mypy/pull/13978">13978</a>)
</ul>
<h2>Documentation Improvements</h2>
<ul>
<li>Various documentation and error message tweaks (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14574">14574</a>)
<li>Improve Generics documentation (Shantanu, PR <a href="https://github.com/python/mypy/pull/14587">14587</a>)
<li>Improve protocols documentation (Shantanu, PR <a href="https://github.com/python/mypy/pull/14577">14577</a>)
<li>Improve dynamic typing documentation (Shantanu, PR <a href="https://github.com/python/mypy/pull/14576">14576</a>)
<li>Improve the Common Issues page (Shantanu, PR <a href="https://github.com/python/mypy/pull/14581">14581</a>)
<li>Add a top-level TypedDict page (Shantanu, PR <a href="https://github.com/python/mypy/pull/14584">14584</a>)
<li>More improvements to getting started documentation (Shantanu, PR <a href="https://github.com/python/mypy/pull/14572">14572</a>)
<li>Move truthy-function documentation from “optional checks” to “enabled by default” (Anders Kaseorg, PR <a href="https://github.com/python/mypy/pull/14380">14380</a>)
<li>Avoid use of implicit optional in decorator factory documentation (Tom Schraitle, PR <a href="https://github.com/python/mypy/pull/14156">14156</a>)
<li>Clarify documentation surrounding install-types (Shantanu, PR <a href="https://github.com/python/mypy/pull/14003">14003</a>)
<li>Improve searchability for module level type ignore errors (Shantanu, PR <a href="https://github.com/python/mypy/pull/14342">14342</a>)
<li>Advertise mypy daemon in README (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14248">14248</a>)
<li>Add link to error codes in README (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14249">14249</a>)
<li>Document that report generation disables cache (Ilya Konstantinov, PR <a href="https://github.com/python/mypy/pull/14402">14402</a>)
<li>Stop saying mypy is beta software (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14251">14251</a>)
<li>Flycheck-mypy is deprecated, since its functionality was merged to Flycheck (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14247">14247</a>)
<li>Update code example in "Declaring decorators" (ChristianWitzler, PR <a href="https://github.com/python/mypy/pull/14131">14131</a>)
</ul>
<h2>Stubtest Improvements</h2>
<p>Stubtest is a tool for testing that stubs conform to the implementations.
<ul>
<li>Improve error message for <tt>__all__</tt>-related errors (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/14362">14362</a>)
<li>Improve heuristics for determining whether global-namespace names are imported (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/14270">14270</a>)
<li>Catch BaseException on module imports (Shantanu, PR <a href="https://github.com/python/mypy/pull/14284">14284</a>)
<li>Associate exported symbol error with <tt>__all__</tt> object_path (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/14217">14217</a>)
<li>Add <tt>__warningregistry__</tt> to the list of ignored module dunders (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/14218">14218</a>)
<li>If a default is present in the stub, check that it is correct (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/14085">14085</a>)
</ul>
<h2>Stubgen Improvements</h2>
<p>Stubgen is a tool for automatically generating draft stubs for libraries.
<ul>
<li>Treat dlls as C modules (Shantanu, PR <a href="https://github.com/python/mypy/pull/14503">14503</a>)
</ul>
<h2>Other Notable Fixes and Improvements</h2>
<ul>
<li>Update stub suggestions based on recent typeshed changes (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/14265">14265</a>)
<li>Fix attrs protocol check with cache (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/14558">14558</a>)
<li>Fix strict equality check if operand item type has custom <tt>__eq__</tt> (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14513">14513</a>)
<li>Don't consider <tt>object</tt> always truthy (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14510">14510</a>)
<li>Properly support union of TypedDicts as dict literal context (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14505">14505</a>)
<li>Properly expand type in generic class with Self and TypeVar with values (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14491">14491</a>)
<li>Fix recursive TypedDicts/NamedTuples defined with call syntax (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14488">14488</a>)
<li>Fix type inference issue when a class inherits from <tt>Any</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/14404">14404</a>)
<li>Fix false positive on generic base class with <tt>six</tt> (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14478">14478</a>)
<li>Don't read scripts without extensions as modules in namespace mode (Tim Geypens, PR <a href="https://github.com/python/mypy/pull/14335">14335</a>)
<li>Fix inference for constrained type variables within unions (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/14396">14396</a>)
<li>Fix <tt>Unpack</tt> imported from typing (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/14378">14378</a>)
<li>Allow trailing commas in <tt>ini</tt> configuration of multiline values (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/14240">14240</a>)
<li>Fix false negatives involving Unions and generators or coroutines (Shantanu, PR <a href="https://github.com/python/mypy/pull/14224">14224</a>)
<li>Fix ParamSpec constraint for types as callable (Vincent Vanlaer, PR <a href="https://github.com/python/mypy/pull/14153">14153</a>)
<li>Fix type aliases with fixed-length tuples (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14184">14184</a>)
<li>Fix issues with type aliases and new style unions (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14181">14181</a>)
<li>Simplify unions less aggressively (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14178">14178</a>)
<li>Simplify callable overlap logic (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14174">14174</a>)
<li>Try empty context when assigning to union typed variables (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14151">14151</a>)
<li>Improvements to recursive types (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14147">14147</a>)
<li>Make non-numeric non-empty FORCE_COLOR truthy (Shantanu, PR <a href="https://github.com/python/mypy/pull/14140">14140</a>)
<li>Fix to recursive type aliases (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14136">14136</a>)
<li>Correctly handle Enum name on Python 3.11 (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14133">14133</a>)
<li>Fix class objects falling back to metaclass for callback protocol (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14121">14121</a>)
<li>Correctly support self types in callable ClassVar (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14115">14115</a>)
<li>Fix type variable clash in nested positions and in attributes (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14095">14095</a>)
<li>Allow class variable as implementation for read only attribute (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14081">14081</a>)
<li>Prevent warnings from causing dmypy to fail (Andrzej Bartosiński, PR <a href="https://github.com/python/mypy/pull/14102">14102</a>)
<li>Correctly process nested definitions in mypy daemon (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14104">14104</a>)
<li>Don't consider a branch unreachable if there is a possible promotion (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/14077">14077</a>)
<li>Fix incompatible overrides of overloaded methods in concrete subclasses (Shantanu, PR <a href="https://github.com/python/mypy/pull/14017">14017</a>)
<li>Fix new style union syntax in type aliases (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/14008">14008</a>)
<li>Fix and optimise overload compatibility checking (Shantanu, PR <a href="https://github.com/python/mypy/pull/14018">14018</a>)
<li>Improve handling of redefinitions through imports (Shantanu, PR <a href="https://github.com/python/mypy/pull/13969">13969</a>)
<li>Preserve (some) implicitly exported types (Shantanu, PR <a href="https://github.com/python/mypy/pull/13967">13967</a>)
</ul>
<h2>Typeshed Updates</h2>
<p>Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see <a href="https://github.com/python/typeshed/commits/main?after=ea0ae2155e8a04c9837903c3aff8dd5ad5f36ebc+0&branch=main&path=stdlib">git log</a> for full list of typeshed changes.
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<ul>
<li>Alessio Izzo
<li>Alex Waygood
<li>Anders Kaseorg
<li>Andrzej Bartosiński
<li>Avasam
<li>ChristianWitzler
<li>Christoph Tyralla
<li>dosisod
<li>Harrison McCarty
<li>Hugo van Kemenade
<li>Hugues
<li>Ilya Konstantinov
<li>Ivan Levkivskyi
<li>Jelle Zijlstra
<li>jhance
<li>johnthagen
<li>Jonathan Daniel
<li>Joshua Bronson
<li>Jukka Lehtosalo
<li>KotlinIsland
<li>Lakshay Bisht
<li>Lefteris Karapetsas
<li>Marc Mueller
<li>Matthew Hughes
<li>Michael Lee
<li>Nick Drozd
<li>Nikita Sobolev
<li>Richard Si
<li>Shantanu
<li>Stas Ilinskiy
<li>Tim Geypens
<li>Tin Tvrtković
<li>Tom Schraitle
<li>Valentin Stanciu
<li>Vincent Vanlaer
</ul>
<p>We’d also like to thank our employer, Dropbox, for funding the mypy core team.</body>
</html>Stas Ilinskiyhttp://www.blogger.com/profile/03698956790898236634noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-57851250809075581612022-11-08T01:54:00.004-08:002022-11-14T09:13:37.846-08:00Mypy 0.991 Released<p>We’ve just uploaded mypy 0.991 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type checker for Python. This release includes new features, performance improvements and bug fixes. You can install it as follows:
<pre>
python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Basic Python 3.11 Support</h2>
<p>Mypy and mypyc now have partial official support for Python 3.11. We provide compiled wheels for 3.11, and many 3.11 stdlib features are supported.
<p>Most new language and typing features are still unsupported or are experimental. Adding support for the remaining 3.11 features is a priority for the mypy team.
<h2>Breaking Change: No Implicit Optional Types for Arguments</h2>
<p>Mypy now disables implicit optional types such as these by default to fix a long-standing incompatibility with <a href="https://peps.python.org/pep-0484/">PEP 484</a>, and they will have to be explicitly enabled:
<pre>
def foo(s: str = None) -> int: ... # Error!
</pre>
<p>Mypy will now only accept the example with an explicit optional type (e.g. <tt>str | None</tt>) for the <tt>s</tt> argument, when using the default options:
<pre>
# s: Optional[str] also works
def foo(s: str | None = None) -> int: ... # OK
</pre>
<p>You can still explicitly enable implicit optional types via <tt>--implicit-optional</tt> or <tt>no_implicit_optional = False</tt> in your mypy config file. We don’t recommend relying on implicit optional types, since they are a non-standard feature, but we have no plans to stop supporting them.
<p>You can also use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase to explicit optional types.
<p>This was contributed by Shantanu:
<ul>
<li>Use <tt>--no-implicit-optional</tt> by default (Shantanu, PR <a href="https://github.com/python/mypy/pull/13401">13401</a>)
<li>Suggest codemod for <tt>--no-implicit-optional</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/13747">13747</a>)
</ul>
<h2>Breaking Change: Namespace Packages Enabled by Default</h2>
<p>Mypy now enables <tt>--namespace-packages</tt> by default (<a href="https://peps.python.org/pep-0420/">PEP 420</a>), so that namespace packages (packages with a missing <tt>__init__.py</tt> file) are supported without any extra configuration.
<p>Refer to <a href="https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-namespace-packages">the documentation of</a> <tt><a href="https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-namespace-packages">--namespace-packages</a></tt> and to <a href="https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-paths-to-modules">Mapping file paths to modules</a> in mypy documentation for more information.
<p>In some cases you may need to use <tt><a href="https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-explicit-package-bases">--explicit-package-bases</a></tt> and to explicitly declare additional package roots that mypy can’t figure out automatically by using the <tt>MYPYPATH</tt> environment variable or using <tt>mypy_path = <dirs></tt> in your config file. Otherwise you may get errors about missing imports.
<p>You can explicitly disable the option by using <tt>--no-namespace-packages</tt> or <tt>namespace_packages = False</tt> in your config file to return to the old behavior. We recommend first trying <tt>--explicit-package-bases</tt> discussed above if you encounter any issues.
<p>This was contributed by Shantanu (PR <a href="https://github.com/python/mypy/pull/9636">9636</a>).
<h2>Recursive Types Enabled By Default</h2>
<p>Mypy support for general recursive types is now official. These were available in mypy 0.981 through the <tt>--enable-recursive-aliases</tt> flag. Now you no longer need to explicitly enable them. Example:
<pre>
# This is now allowed by default
NaiveJSON = str | list["NaiveJSON"] | dict[str, "NaiveJSON"]
test_data: NaiveJSON = {"foo": {"bar": "baz"}} # OK
</pre>
<p>Note that you will need to use string escapes on the right hand side (e.g. <tt>"</tt><tt>NaiveJSON</tt><tt>"</tt>) if you define recursive types outside of stub files, since Python doesn’t support forward references at runtime. Also, mypy generally doesn’t infer recursive types by default. Similar to TypedDict types, you will often need to explicitly annotate a variable with a recursive type or mypy will try to infer a non-recursive type instead.
<p>You can still disable recursive types using <tt>--disable-recursive-aliases</tt> if they cause any problems. Please open an issue on <a href="https://github.com/python/mypy/issues">the</a> <a href="https://github.com/python/mypy/issues">mypy</a> <a href="https://github.com/python/mypy/issues">issue</a> <a href="https://github.com/python/mypy/issues">tracker</a> if this is the case.
<p>See “Experimental Support for General Recursive Types” in <a href="https://mypy-lang.blogspot.com/2022/09/mypy-0981-released.html">the mypy 0.981 release blog post</a> for more details.
<p>This change was contributed by Ivan Levkivskyi in (PR <a href="https://github.com/python/mypy/pull/13516">13516</a>), (PR <a href="https://github.com/python/mypy/pull/13852">13852</a>) and (PR <a href="https://github.com/python/mypy/pull/13754">13754</a>).
<h2>Error Codes Shown by Default</h2>
<p>Mypy now shows error codes at the end of each error message by default, within square brackets. Example:
<pre>
error:
Unsupported operand types for + ("int" and "str") [operator]
</pre>
<p>This makes it easier to silence only specific error codes on a line by using <tt># type: ignore[<error-code>]</tt>. Example:
<pre>
print(1 + "x") # type: ignore[operator]
</pre>
<p>You can find helpful information about specific errors by looking up the error code in <a href="https://mypy.readthedocs.io/en/stable/error_code_list.html">the documentation</a>.
<p>You can hide error codes by using <tt>--hide-error-codes</tt> or by adding <tt>show_error_codes = False</tt> to your configuration file.
<p>This was contributed by Marc Mueller (PR <a href="https://github.com/python/mypy/pull/13542">13542</a>).
<h2>Safe Handling of Empty Function Bodies</h2>
<p>For historical reasons, mypy used to always allow trivial function/method bodies (e.g. a body with only a single <tt>pass</tt> statement and/or a docstring), even if this is not type safe. Example:
<pre>
# Error: Missing return statement (no error before 0.990)
def some_func(arg: str) -> int:
pass
</pre>
<p>This could hide bugs and was a generally confusing behavior. Mypy is now handling such empty bodies safely. In the example above you will now get an error (unless you are using <tt>--no-strict-optional</tt>). Mypy only allows an empty/trivial body in a method with a non-optional return type if the method is abstract:
<pre>
class Base(ABC):
@abstractmethod
def must_implement_in_subclass(self, arg: str) -> int:
pass # Still OK
</pre>
<p>Additionally, mypy now flags unsafe <tt>super()</tt> calls to a method with an empty body that’s decorated with <tt>@abstractmethod</tt>. Mypy will now issue an error in this case.
<p>To disable this functionality, use the <tt>--allow-empty-bodies</tt> flag.
<p>This change was contributed by Ivan Levkivskyi in (PR <a href="https://github.com/python/mypy/pull/13729">13729</a>).
<h2>Enabling Experimental Features Individually</h2>
<p>Experimental mypy features can now be enabled individually. With this change, using <tt>--enable-incomplete-features</tt> to enable all of them becomes deprecated and the recommended way forward is to enable experimental features individually with <tt>--enable-incomplete-features=FEATURE</tt>.
<p>This change was contributed by Ivan Levkivskyi and Nikita Sobolev in (PR <a href="https://github.com/python/mypy/pull/13790">13790</a>).
<h2>Configuring Packages/Modules in the Config File</h2>
<p>It is now possible to tell mypy to implicitly type check specific packages by using the options <tt>modules</tt> and <tt>packages</tt> in the configuration file, without having to explicitly include these on the command line. These options take a comma separated list of packages which will be checked by mypy if none are given on the command line.
<p>Mypy <i>will not</i> recursively type check any submodules of the provided modules by <tt>modules</tt> and <i>will</i> recursively type check any submodules of the provided modules by <tt>packages</tt>.
<p>These options may only be set in the global section. See also <a href="https://mypy.readthedocs.io/en/latest/config_file.html#confval-modules">the documentation</a>.
<p>This feature was contributed by sameer-here (PR <a href="https://github.com/python/mypy/pull/12639">12639</a>).
<h2>Warn about Variable Annotations in Unchecked Functions</h2>
<p>Mypy will no generate a note if you use a type annotation in a function without a type annotation (and you are not using <tt>--check-untyped-defs</tt>), since these annotations have no effect. Example:
<pre>
def foo():
x: int = bar()
print(x)
</pre>
<p>This is treated as a warning, so it doesn’t cause a mypy run to fail:
<pre>
$ mypy prog.py
prog.py:2: note: By default the bodies of untyped functions
are not checked, consider using --check-untyped-defs
[annotation-unchecked]
Success: no issues found in 1 source file
</pre>
<p>This was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/13851">13851</a>).
<h2>Error Code for Using an Abstract Class as type[T]</h2>
<p>Mypy disallows using an abstract type object (ABC) if type <tt>type[T]</tt> is expected. This would be unsafe, since mypy always allows calling <tt>type[T]</tt> values to instantiate objects, and ABCs can’t be instantiated.
<p>Now this error has the dedicated error code <tt>type-abstract</tt>, and you can use <tt>--disable-error-code type-abstract</tt> to disable this check, since it can generate undesirable errors in some use cases. Example:
<pre>
import abc
class A(abc.ABC):
@abc.abstractmethod
def m(self) -> None: pass
class C(A):
def m(self) -> None: print('m')
def check(o: object t: type[A]) -> bool:
return isinstance(o, t)
# Error: Only concrete class can be given here [type-abstract]
check(C(), A)
check(C(), C) # OK
</pre>
<p>This was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/13785">13785</a>).
<h2>Performance Improvements</h2>
<p>Mypy includes a potential fix for a performance regression edge case introduced in mypy 0.982:
<ul>
<li>Revert literal type change in <tt>builtins.</tt><tt>sum</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/13961">13961</a>)
</ul>
<h2>Changes to Error Reporting and Messages</h2>
<ul>
<li>Return exit status 0 if there are only notes and no errors (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13879">13879</a>)
<li>Generate an error if a function object is used in a boolean context, with the <tt>truthy-function</tt> error code, even if the <tt>truthy-bool</tt> error code is disabled (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/13686">13686</a>)
<li>Silence errors from third-party packages in mypy daemon (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/13768">13768</a>)
<li>Preserve file order of messages during successive daemon runs (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/13780">13780</a>)
<li>Suggest additional <tt>types-*</tt> packages from typeshed (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/13698">13698</a>)
<li>Better diagnostic for conditional function mismatch (Shantanu, PR <a href="https://github.com/python/mypy/pull/13604">13604</a>)
<li>Use consistent capitalization for <tt>TypeVar</tt> (Marti Raudsepp, PR <a href="https://github.com/python/mypy/pull/13687">13687</a>)
<li>Suggest using upper bound for unbound type variable (Shantanu, PR <a href="https://github.com/python/mypy/pull/13730">13730</a>)
<li>Show error codes for some notes (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13880">13880</a>)
<li>Suggest using a protocol if trying to use a module as a type (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/13861">13861</a>)
<li>Improve error message for <tt>--strict-concatenate</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/13777">13777</a>)
<li>Improve error message for implicitly abstract functions (Shantanu, PR <a href="https://github.com/python/mypy/pull/13776">13776</a>)
<li>Mention implicit export on missing attribute access (Shantanu, PR <a href="https://github.com/python/mypy/pull/13917">13917</a>)
<li>Always mention explicit export when relevant (Shantanu, PR <a href="https://github.com/python/mypy/pull/13925">13925</a>)
<li>Fix error code when reporting an invalid Literal type (Shantanu, PR <a href="https://github.com/python/mypy/pull/13763">13763</a>)
<li>Replace invalid <tt>__set__</tt> with <tt>__get__</tt> in messages (Ilya Konstantinov, PR <a href="https://github.com/python/mypy/pull/13913">13913</a>)
</ul>
<h2>Mypyc Fixes and Improvements</h2>
<ul>
<li>Add support for building mypyc code on WASM (Ethan Smith and Shantanu, PR <a href="https://github.com/python/mypy/pull/13446">13446</a>)
<li>Fix C errors about shifting negative integers (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/13876">13876</a>)
</ul>
<h2>Documentation Updates</h2>
<p>Several parts of the documentation received major updates.
<ul>
<li>Major update to "Using mypy with existing codebase" (Shantanu, PR <a href="https://github.com/python/mypy/pull/13683">13683</a>)
<li>Update cheat sheet (PR <a href="https://github.com/python/mypy/pull/13873">13873</a>, PR <a href="https://github.com/python/mypy/pull/13679">13679</a>) (Shantanu)
<li>Update “Runtime troubles” (Shantanu, PR <a href="https://github.com/python/mypy/pull/13680">13680</a>)
<li>Mention <tt>files</tt> config file option in "Specifying code to check" (Shantanu, PR <a href="https://github.com/python/mypy/pull/13682">13682</a>)
<li>Make language more consistent (Shantanu, PR <a href="https://github.com/python/mypy/pull/13677">13677</a>)
<li>Update “Getting started” (Shantanu, PR <a href="https://github.com/python/mypy/pull/13734">13734</a>)
<li>Update “Type inference and annotations” (Shantanu, PR <a href="https://github.com/python/mypy/pull/13736">13736</a>)
<li>Discuss user defined protocols before built-in protocols (Shantanu, PR <a href="https://github.com/python/mypy/pull/13737">13737</a>)
<li>Reorder sections in “Running mypy” (Shantanu, PR <a href="https://github.com/python/mypy/pull/13738">13738</a>)
<li>Improve "Precise typing of alternative constructors" example (Jelle Zijlstra)
<li>Improve “Getting started” docs (Shantanu, PR <a href="https://github.com/python/mypy/pull/13875">13875</a>)
<li>Update “Extending mypy” docs (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/13924">13924</a>)
<li>Add clear warning about stubtest code execution (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/13927">13927</a>)
</ul>
<h2>Stubgen Improvements</h2>
<p>Stubgen is a tool for automatically generating draft stubs for libraries.
<ul>
<li>Introduce an object-oriented system for extracting function signatures (Chad Dombrova, PR <a href="https://github.com/python/mypy/pull/13473">13473</a>)
<li>Add known return types to magic methods (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/13909">13909</a>)
</ul>
<h2>Stubtest Improvements</h2>
<p>Stubtest is a tool for testing that stubs conform to the implementations.
<ul>
<li>Detect abstract properties mismatches (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/13647">13647</a>)
<li>Catch SyntaxError from <tt>inspect.getsourcelines</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/13848">13848</a>)
</ul>
<h2>Other Notable Fixes and Improvements</h2>
<ul>
<li>Detect invalid ParamSpec annotations used with <tt>*args</tt> and <tt>**kwargs</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/13892">13892</a>)
<li>Fix crash with generic class definition in function (Michael Lee, PR <a href="https://github.com/python/mypy/pull/13678">13678</a>)
<li>Fix joining a function against metaclass-using object constructors (Michael Lee, PR <a href="https://github.com/python/mypy/pull/13648">13648</a>)
<li>Fixes to attrs magic attribute handling (Tin Tvrtković and Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/13522">13522</a>)
<li>Support <tt>__attrs_init__</tt> method in attrs classes (Spencer Brown, PR <a href="https://github.com/python/mypy/pull/13865">13865</a>)
<li>Fix crash on match statement with value restricted TypeVar (Shantanu, PR <a href="https://github.com/python/mypy/pull/13728">13728</a>)
<li>Fix crash in match statement with unmatchable class pattern (Shantanu)
<li>Fix unsound variance (Shantanu, PR <a href="https://github.com/python/mypy/pull/13714">13714</a>)
<li>Fix crash with report generation on namespace packages (Shantanu, PR <a href="https://github.com/python/mypy/pull/13733">13733</a>)
<li>Remove use of LiteralString in builtins (Shantanu, PR <a href="https://github.com/python/mypy/pull/13743">13743</a>)
<li>Treat <tt>__dataclass_fields__</tt> as a ClassVar (Shantanu, PR <a href="https://github.com/python/mypy/pull/13721">13721</a>)
<li>Respect per-module <tt>follow_import</tt> for empty folders (Shantanu, PR <a href="https://github.com/python/mypy/pull/13758">13758</a>)
<li>Fix a crash related to dataclasses and type aliases (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13759">13759</a>)
<li>Add install-types extra that depends on pip (David Runge, PR <a href="https://github.com/python/mypy/pull/13739">13739</a>)
<li>Restore Type vs Callable special-casing that was broken in refactoring (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13784">13784</a>)
<li>Fix module and protocol subtyping and hasattr with a module (Shantanu, PR <a href="https://github.com/python/mypy/pull/13778">13778</a>)
<li>Make join of recursive types more robust (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13808">13808</a>)
<li>Fix minor issues with <tt>**kwargs</tt> that use TypedDict unpacking (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13854">13854</a>)
<li>Fix crash on missing indirect dependencies (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13847">13847</a>)
<li>Ignore promotions when simplifying unions (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13781">13781</a>)
<li>Fall back to <tt>FORCE_COLOR</tt> environment variable if <tt>MYPY_FORCE_COLOR</tt> is not present (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/13814">13814</a>)
</ul>
<h2>Typeshed Updates</h2>
<p>Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see <a href="https://github.com/python/typeshed/commits/main?after=51e18a860129b792123a088467a431cd044b2769+0&branch=main&path=stdlib">git log</a> for full list of typeshed changes.
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<ul>
<li>Alex Waygood
<li>Bas van Beek
<li>Ben Raz
<li>Chad Dombrova
<li>David Runge
<li>Ethan Smith
<li>Ilya Konstantinov
<li>Ivan Levkivskyi
<li>iyanging
<li>Jared Hance
<li>Jelle Zijlstra
<li>Jeroen Van Goey
<li>Jinze Wu
<li>Jukka Lehtosalo
<li>Kevin Kirsche
<li>KotlinIsland
<li>Marc Mueller
<li>Marti Raudsepp
<li>Matt Wozniski
<li>Michael Lee
<li>Nikita Sobolev
<li>pranavrajpal
<li>Richard Si
<li>Ryan Soklaski
<li>sameer-here
<li>Shantanu
<li>Spencer Brown
<li>Stas Ilinskiy
<li>Tim D. Smith
<li>Tin Tvrtković
<li>Valentin Stanciu
</ul>
<p>We’d also like to thank our employer, Dropbox, for funding the mypy core team.Unknownnoreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-16834000332183403062022-09-26T11:37:00.003-07:002022-09-26T15:13:03.555-07:00Mypy 0.981 Released<p>
</p>We’ve just uploaded mypy 0.981 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type checker for Python. This release includes new features, performance improvements and bug fixes. You can install it as follows:
<pre> python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
</p><h2>Support for Python 3.6 and 2 Dropped</h2>
<p>Support for Python 2 has been completely removed in this release.
</p><p>Support for Python 3.6 has also been dropped, since Python 3.6 has reached its end of life. It is still possible to target Python 3.6 using <tt>--python-version</tt> in future mypy versions, but no bugs will be fixed that affect only Python 3.6 (unless they are regressions). Also note that typeshed just recently dropped Python 3.6 support, so standard library features only available in Python 3.6 will not be supported.
</p><p>The implementation was jointly contributed by Shantanu, Nikita Sobolev and Ivan Levkivskyi.
</p><h2>Generate Error on Unbound TypeVar Return Type</h2>
<p>Code like this will now generate an error, since the value of <tt>T</tt> cannot be inferred in calls:
</p><pre> from typing import TypeVar
T = TypeVar("T")
# Error: A function returning TypeVar should receive at least one
# argument containing the same Typevar
def f() -> T: ...
</pre>
<p>Having an unbound type variable in a nested position (e.g. <tt>list[T]</tt>) is still accepted in a return type, since it has valid use cases. This was contributed by Aurélien Jaquier (PR <a href="https://github.com/python/mypy/pull/13166">13166</a>).
</p><h2>Methods with Empty Bodies in Protocols Are Abstract</h2>
<p>Any method with an empty body in a protocol is now correctly treated as implicitly abstract and must be implemented even if a class explicitly inherits the protocol:
</p><pre> from typing import Protocol
class P(Protocol):
# "..." is the literal ellipsis and indicates an empty body
def meth(self) -> int: ...
class Cls(P):
pass
# Error: Cannot instantiate abstract class "Cls" with abstract
# attribute "method"
Cls()
</pre>
<p>This was contributed by Thomas MK (PR <a href="https://github.com/python/mypy/pull/12118">12118</a>).
</p><h2>Implicit Optional Types Will Be Disabled by Default</h2>
<p>A future mypy feature release (possibly the next one after 0.98x) will disable implicit optional types such as these by default, and they will have to be explicitly enabled:
</p><pre> def foo(s: str = None) -> int: ... No error currently
foo(None) # Ok
</pre>
<p>In the future mypy will only accept the example with an explicit optional type (e.g. <tt>str | None</tt>) for the <tt>s</tt> argument, when using the default options:
</p><pre> # s: Optional[str] also works
def foo(s: str | None = None) -> int: ...
foo(None) # No change to callers
</pre>
<p>To prepare for the change, you can set the relevant configuration option explicitly. Either disable implicit optional types by using <tt>--no-implicit-optional</tt>, or <tt>no_implicit_optional = True</tt> in your mypy configuration file, or enable them via <tt>--implicit-optional</tt> or <tt>no_implicit_optional = False</tt>. We don’t recommend relying on implicit optional types, since they are a non-standard feature, but we have no plans to stop supporting them.
</p><p>We hope to provide a migration tool that will automatically switch implicit optional types to explicit ones in function signatures.
</p><h2>Precise Types for **<tt>kwds</tt> Using TypedDict</h2>
<p>Mypy now supports precise type annotations for <tt>kwds</tt> parameters. You can use this feature as following:
</p><pre> from typing import TypedDict
from typing_extensions import Unpack
class Style(TypedDict, total=False):
margin: int
sticky: bool
def add_button(label: str, **kwds: Unpack[Style]) -> None:
...
def add_check_box(active: bool, **kwds: Unpack[Style]) -> None:
...
add_button("Cancel", margin=0, sticky=False) # This works
tight: Style = {"margin": 0}
add_button("OK", **tight) # This works as well
</pre>
<p>You can alternatively use <tt>Required[...]</tt> and <tt>NotRequired[...]</tt> TypedDict annotations to control whether a keyword argument is required or not. Note that arbitrary extra keywords are not allowed for such functions (this is consistent with how mypy currently handles TypedDicts). Although this feature is complete, <tt>Unpack[...]</tt> is still considered experimental, so you will need to use <tt>--enable-incomplete-features</tt> to enable it.
</p><p>This feature was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/13471">13471</a>).
</p><h2>Experimental Support for General Recursive Types</h2>
<p>Until recently mypy only supported recursively defined classes (e.g. trees), but not arbitrary recursive types. In this version we add (experimental) support for arbitrary recursively defined types, including type aliases, TypedDicts, NamedTuples, and so on. This example uses a recursively defined type alias:
</p><pre> from typing import TypeVar, Sequence
T = TypeVar("T")
# String literal escaping needed to avoid NameError at runtime
Nested = Sequence[T | "Nested[T]"]
def flatten(seq: Nested[T]) -> list[T]:
result = []
for item in seq:
if isinstance(item, list):
result.extend(flatten(item))
else:
result.append(item)
return result
flatten([1, [2, 3]]) # This works, inferred type is <tt>list[int]</tt>
</pre>
<p>This feature can be enabled using <tt>--enable-recursive-aliases</tt>. If mypy doesn’t work as expected with some recursive types, you can try adding more explicit annotations, and/or using covariant collections (e.g. <tt>Sequence</tt> instead of <tt>list</tt>). Please file an issue on the <a href="https://github.com/python/mypy/issues">issue</a> <a href="https://github.com/python/mypy/issues">tracker</a> if you think you have found a bug.
</p><p>List of relevant PRs:
</p><ul><li>Enable recursive type aliases behind a flag (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13297">13297</a>)
</li><li>Simplify types in some error messages (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13326">13326</a>)
</li><li>Support recursive TypedDicts (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13373">13373</a>)
</li><li>Support recursive named tuples (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13371">13371</a>)
</li><li>Fail gracefully on diverging recursive type aliases (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13352">13352</a>)
</li><li>Fail gracefully on invalid and/or unsupported recursive type aliases (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13336">13336</a>)
</li><li>Handle interactions between recursive aliases and recursive instances (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13328">13328</a>)
</li><li>Fix crash on deferred upper bound with recursive aliases enabled (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13410">13410</a>)
</li><li>Remove <tt>Optional[...]</tt> special-casing to avoid infinite recursion (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13357">13357</a>)
</li></ul>
<h2>Generic NamedTuples and TypedDicts</h2>
<p>Mypy now supports defining generic TypedDicts, NamedTuples, and user defined tuple types. You can use either the class or call syntax for this:
</p><pre> from typing import Generic, TypeVar
from typing_extensions import TypedDict # From "typing" on Python 3.11
T = TypeVar("T")
class Param(TypedDict, Generic[T]):
name: str
value: T
Opt = TypedDict("Opt", {"value": T, "is_set": bool})
def apply(param: Param[T]) -> T: ...
x = apply({"name": "test", "value": 42}) # Inferred type is "int"
</pre>
<b>Note:</b> While you can freely use this feature in stub files, if you want to use it in source files, you will need to either use Python 3.11 (which is not officially supported by mypy yet), import <tt>TypedDict</tt>/<tt>NamedTuple</tt> from <tt>ty</tt><tt>ping_extensions</tt>, or use an <tt>if TYPE_CHECKING: ...</tt> block.
<p>List of relevant PRs:
</p><ul><li>Enable generic TypedDicts (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13389">13389</a>)
</li><li>Enable generic NamedTuples (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13396">13396</a>)
</li></ul>
<h2>Better Support for Callable Attributes</h2>
<p>Mypy now has better support for instance attributes with <tt>Callable[...]</tt> types. Previously, mypy couldn’t reliably distinguish between callable instance attributes and method aliases. Now there are consistent rules. If a variable is defined using and assignment and/or annotation in a class body and has a callable type, it is an instance attribute if both these conditions are true:
</p><ul><li>There is an explicit annotation, and it is <i>not</i> a <tt>ClassVar[...]</tt>.
</li><li>The variable name is <i>not</i> a special dunder method name, such as <tt>__add__</tt>.
</li></ul>
<p>Conversely, such an assignment/annotation defines a method in these cases:
</p><ul><li>There is no explicit annotation, or there is a <tt>ClassVar[...]</tt> annotation.
</li><li>The variable name is a special dunder method name.
</li></ul>
<p>Example:
</p><pre> from typing import ClassVar, Callable
class Test:
runner: Callable[[], None] # An instance variable
def hook(self) -> None: ...
self.runner = lambda: print("pass")
legacy_hook = hook # A method
other_hook: ClassVar[Callable[[Test], None]] # Also a method
Test.other_hook = lambda self: None
t = Test()
t.legacy_hook()
t.runner()
t.other_hook()
</pre>
<p>This feature was contribute by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/13400">13400</a>).
</p><h2>Per-Module Error Code Configuration</h2>
<p>You can now disable and/or enable individual error codes per module and per directory using config files and/or inline <tt># mypy:</tt> comments. Example:
</p><pre> # mypy.ini
[mypy]
strict = True
[mypy-tests.*]
allow_untyped_defs = True
allow_untyped_calls = True
disable_error_code = var-annotated
</pre>
<pre> # source.py
x = [] # Error: Need type annotation for "x"
</pre>
<pre> # tests/foo.py
x = [] # OK
</pre>
<pre> # tests/bar.py
# mypy: enable-error-code="var-annotated"
x = [] # Error: Need type annotation for "x"
</pre>
<p>Note that these per-directory settings act as incremental overrides. The precedence is the following:
</p><ul><li>Command line options and/or the main section of a config file set global codes.
</li><li>Config sections <i>adjust</i> them per glob/module.
</li><li>Inline <tt># mypy:</tt> comments adjust them again.
</li></ul>
<p>You can, for example, enable an error code globally, disable it for all tests in the config file, and then re-enable it in a particular file by using an inline comment.
</p><p>This feature was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/13502">13502</a>).
</p><h2>Experimental Support for Interactive Inspection of Expressions</h2>
<p>Mypy now has an experimental support for various static inspections using the mypy daemon <tt>dmypy inspect</tt> command. These inspections are currently included:
</p><ul><li>Print the type of an expression at given location.
</li><li>Print the attributes defined for a given expression.
</li><li>Go to definition of a reference expression (name or attribute).
</li></ul>
<p>Note that you can run this only after the file has been type-checked by the daemon, for example by using <tt>dmypy check</tt> or <tt>dmypy run</tt>. Basic usage is like this:
</p><pre> dmypy inspect [--show type|attrs|definition] \</pre><pre><span> </span><span> </span>path/to/file.py:line:column[:end_line:end_column]
</pre>
<p>Please read <a href="https://mypy.readthedocs.io/en/latest/mypy_daemon.html#statically-inspect-expressions">the docs</a> for more details. This feature was contributed by Ivan Levkivskyi (PR <a href="https://github.com/python/mypy/pull/13209">13209</a>).
</p><h2>Mypyc Improvements</h2>
<p>Mypyc compiles Python modules to C extensions and is bundled with mypy. It uses standard Python type hints to generate fast code (<a href="https://mypyc.readthedocs.io/en/latest/">documentation</a>).
</p><ul><li>Support <tt>async for</tt> as a statement and in comprehensions (Michael J. Sullivan, PR <a href="https://github.com/python/mypy/pull/13444">13444</a>)
</li><li>Support <tt>async with</tt> (Michael J. Sullivan, PR <a href="https://github.com/python/mypy/pull/13442">13442</a>)
</li><li>Fix clang warning on different signs integer (Paul m. p. Peny, PR <a href="https://github.com/python/mypy/pull/13239">13239</a>)
</li><li>Fix AttributeError message (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/13382">13382</a>)
</li><li>Fix <tt>__call__</tt> subclasses (Ken Jin, PR <a href="https://github.com/python/mypy/pull/13152">13152</a>)
</li><li>Fix <tt>setup</tt> conflict with attributes named <tt>up</tt> (davfsa, PR <a href="https://github.com/python/mypy/pull/13012">13012</a>)
</li><li>Fix bad C generated for multiple assignment (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/13147">13147</a>)
</li><li>Update, simplify check version test (Shantanu, PR <a href="https://github.com/python/mypy/pull/13125">13125</a>)
</li></ul>
<h2>Documentation Updates</h2>
<ul><li>Update theme to furo (Michael Wentz, PR <a href="https://github.com/python/mypy/pull/13345">13345</a>)
</li><li>Use ParamSpec in "Declaring decorators" (Ilya Konstantinov, PR <a href="https://github.com/python/mypy/pull/13237">13237</a>)
</li><li>Fix protocols documentation (Zsolt Cserna, PR <a href="https://github.com/python/mypy/pull/13137">13137</a>)
</li><li>Prefer f-strings over format and underscores in numeric literals in docs (Kevin Kirsche, PR <a href="https://github.com/python/mypy/pull/13317">13317</a>)
</li><li>Use GitHub's zipball as alternative to 'git+https' in README.md (Peter Badida, PR <a href="https://github.com/python/mypy/pull/13208">13208</a>)
</li></ul>
<h2>Stubgen Improvements</h2>
<p>Stubgen is a tool for automatically generating draft stubs for libraries.
</p><ul><li>Allow passing arguments to <tt>stubgen.main</tt> (Matthew Woehlke, PR <a href="https://github.com/python/mypy/pull/13095">13095</a>)
</li><li>Increase import timeout (Matthew Woehlke, PR <a href="https://github.com/python/mypy/pull/13109">13109</a>)
</li></ul>
<h2>Stubtest Improvements</h2>
<p>Stubtest is a tool for testing that stubs conform to the implementations.
</p><ul><li>Fallback to <tt>getattr_static</tt> on AttributeError (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/13285">13285</a>)
</li><li>Reduce false positives on runtime type aliases (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/13116">13116</a>)
</li><li>Catch-all for errors from the runtime (Shantanu, PR <a href="https://github.com/python/mypy/pull/13160">13160</a>)
</li><li>Allow stubtest to ignore Python 2 only magic methods (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/13290">13290</a>)
</li><li>Improve docs (Shantanu, PR <a href="https://github.com/python/mypy/pull/13293">13293</a>)
</li><li>Ignore <tt>__pyx_vtable__</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/13302">13302</a>)
</li><li>Improve signature checking (Shantanu, PR <a href="https://github.com/python/mypy/pull/13307">13307</a>)
</li><li>Show path to stub file (Shantanu, PR <a href="https://github.com/python/mypy/pull/13342">13342</a>)
</li><li>Allow stubtest to raise errors on abstract state mismatch (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/13323">13323</a>)
</li><li>Fix broken error message for async/sync mismatch (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/13414">13414</a>)
</li><li>Don't error for a missing submodule if the submodule name is private (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/13417">13417</a>)
</li><li>Ignore <tt>__vectorcalloffset__</tt> (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/13416">13416</a>)
</li><li>Use single line error message (Shantanu, PR <a href="https://github.com/python/mypy/pull/13301">13301</a>)
</li><li>Verify the contents of <tt>__all__</tt> in a stub (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/12214">12214</a>)
</li><li>Fix error for <tt>Protocol.__init__</tt> and <tt>__annotations__</tt> (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/13179">13179</a>)
</li><li>Fix <tt>custom_typeshed_dir</tt> regression (PR <a href="https://github.com/python/mypy/pull/13658">13658</a>, PR <a href="https://github.com/python/mypy/pull/13656">13656</a>) (Shantanu)
</li></ul>
<h2>Miscellaneous New Features</h2>
<ul><li>Enable support for decorated properties where possible (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13409">13409</a>)
</li><li>Make any callable compatible with <tt>(*args: Any, kwargs: Any)</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/11203">11203</a>)
</li><li>Allow generic decorators on abstract classes (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13398">13398</a>)
</li><li>Print and show error end locations (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13148">13148</a>)
</li><li>Basic support for <tt>typing_extensions.NamedTuple</tt> (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/13178">13178</a>)
</li><li>Union types: Support narrowing to <tt>Ellipsis</tt> (<tt>...</tt>) cases of <tt>Unions</tt> (László Vaskó, PR <a href="https://github.com/python/mypy/pull/13157">13157</a>)
</li></ul>
<h2>Other Notable Fixes and Improvements</h2>
<ul><li>Allow unpacking from TypeVars with iterable bounds (PR <a href="https://github.com/python/mypy/pull/13644">13644</a>, PR <a href="https://github.com/python/mypy/pull/13425">13425</a>) (Shantanu)
</li><li>Fix error codes option serialization (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13523">13523</a>)
</li><li>Fix daemon crashes related to ParamSpec and TypeVarTuple (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/13381">13381</a>)
</li><li>Allow stubs to use newer syntax than 3.7 (Shantanu, PR <a href="https://github.com/python/mypy/pull/13500">13500</a>)
</li><li>Fix <tt>--custom-typeshed-dir</tt> handling (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13629">13629</a>)
</li><li>Remove blocking special cased error for bool subclass (wookie184, PR <a href="https://github.com/python/mypy/pull/13420">13420</a>)
</li><li>Remove useless parameter <tt>script_path</tt> of <tt>mypy.main()</tt> and make arguments keyword-only (Jingchen Ye, PR <a href="https://github.com/python/mypy/pull/13399">13399</a>)
</li><li>Fix type inference for tuples in iterable context (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13406">13406</a>)
</li><li>Fix type narrowing of TypedDict value with key name in final variable (Jingchen Ye, PR <a href="https://github.com/python/mypy/pull/11813">11813</a>)
</li><li>Fix crash from invalid location in aliased types (Michael Krasnyk, PR <a href="https://github.com/python/mypy/pull/12745">12745</a>)
</li><li>Advertise typing status via Trove classifier (Mike Fiedler, PR <a href="https://github.com/python/mypy/pull/13350">13350</a>)
</li><li>Use a better colour for gray in mypy output (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13338">13338</a>)
</li><li>Support type aliases in metaclasses (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/13335">13335</a>)
</li><li>Handle files ending with <tt>__init__</tt> better (Shantanu, PR <a href="https://github.com/python/mypy/pull/13314">13314</a>)
</li><li>Respect <tt>tuple.__getitem__</tt> from typeshed (Shantanu, PR <a href="https://github.com/python/mypy/pull/13313">13313</a>)
</li><li>Make subtype checks more consistent in edge cases (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13303">13303</a>)
</li><li>Fix <tt>--custom-typeshed-dir</tt> crash (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/13296">13296</a>)
</li><li>Ensure builtin modules are from typeshed sooner (Konstantin, PR <a href="https://github.com/python/mypy/pull/13155">13155</a>)
</li><li>Disallow bytes in TypeVar, NewType, and TypedDict names (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/13273">13273</a>)
</li><li>Prohibit bytes literals in named tuples (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/13271">13271</a>)
</li><li>Suggest using a newer Python version if possibly needed (Shantanu, PR <a href="https://github.com/python/mypy/pull/13197">13197</a>)
</li><li>Check implicit None return is valid when using <tt>--no-warn-no-return</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/13219">13219</a>)
</li><li>Fix site package on MYPYPATH check (Shantanu, PR <a href="https://github.com/python/mypy/pull/13223">13223</a>)
</li><li>Make <tt>None</tt> compatible with <tt>SupportsStr</tt> protocol (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/13184">13184</a>)
</li><li>Fix caching of PEP 561 namespace packages (Shantanu, PR <a href="https://github.com/python/mypy/pull/13124">13124</a>)
</li><li>Improve error message for direct <tt>__init__</tt> calls (Shantanu, PR <a href="https://github.com/python/mypy/pull/13183">13183</a>)
</li><li>Allow nonlocal in function scoped classes (Shantanu, PR <a href="https://github.com/python/mypy/pull/13158">13158</a>)
</li><li>Support for Python 3.11's "safe_path" in pyinfo (Shantanu, PR <a href="https://github.com/python/mypy/pull/13164">13164</a>)
</li><li>Generate error when using <tt>NoneType</tt> instead of <tt>None</tt> as a type (Jakub Strnad, PR <a href="https://github.com/python/mypy/pull/13153">13153</a>)
</li><li>Add musllinux wheel support, Use 'official' llvm build for compilation (Ben Raz, PR <a href="https://github.com/python/mypy/pull/13228">13228</a>)
</li><li>Skip musllinux wheels, update for lxml changes (Shantanu, PR <a href="https://github.com/python/mypy/pull/13129">13129</a>)
</li></ul>
<h2>Typeshed Updates</h2>
<p>Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see <a href="https://github.com/python/typeshed/commits/master?after=a92da58328aa259184ff45bb7408e82426fb563e+0&branch=master&path=stdlib">git log</a> for full list of typeshed changes.
</p><h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
</p><ul><li>Alex Waygood
</li><li>anilbey
</li><li>Aurélien Jaquier
</li><li>Ben Raz
</li><li>davfsa
</li><li>Ilya Konstantinov
</li><li>Ivan Levkivskyi
</li><li>Jakub Strnad
</li><li>Jared Hance
</li><li>Jelle Zijlstra
</li><li>Jingchen Ye
</li><li>Jukka Lehtosalo
</li><li>Ken Jin
</li><li>Kevin Kirsche
</li><li>Konstantin
</li><li>KotlinIsland
</li><li>László Vaskó
</li><li>Marc Mueller
</li><li>Matthew Woehlke
</li><li>Michael Krasnyk
</li><li>Michael Sullivan
</li><li>Michael Wentz
</li><li>Mike Fiedler
</li><li>Nikita Sobolev
</li><li>Patryk Gałczyński
</li><li>Paul m. p. Peny
</li><li>Peter Badida
</li><li>Richard Si
</li><li>Shantanu
</li><li>Thomas MK
</li><li>wookie184
</li><li>Zsolt Cserna
</li><li>Zsolt Dollenstein
</li></ul>
<p>We’d also like to thank our employer, Dropbox, for funding the mypy core team.
</p>Jared Hancehttp://www.blogger.com/profile/13451114101069297635noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-240934064958474612022-07-19T08:06:00.002-07:002022-07-19T08:06:45.636-07:00Mypy 0.971 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 0.971 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type checker for Python. This release includes new features, performance improvements and bug fixes. You can install it as follows:
<pre>
python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Last Release Officially Supporting Python 2 and 3.6</h2>
<p>Support for Python 2 will be completely removed in the next mypy feature release after this one, mypy 0.980.
<p>Support for Python 3.6 will also be dropped in mypy 0.980, since Python 3.6 has reached its end of life. It will be still possible to target Python 3.6 using <tt>--python-version</tt> in future mypy versions, but no bugs will be fixed that affect only Python 3.6 (unless they are regressions). Also note that typeshed just recently dropped Python 3.6 support, so standard library features only available in Python 3.6 will not be supported.
<h2>Mypyc Improvements and Fixes</h2>
<p>Mypyc compiles Python modules to C extensions and is bundled with mypy. It uses standard Python type hints to generate fast code (<a href="https://mypyc.readthedocs.io/en/latest/">documentation</a>).
<ul>
<li>Speed up accessing always defined native attributes (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12600">12600</a>)
<li>Reduce the overhead of reference counting (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12805">12805</a>, PR <a href="https://github.com/python/mypy/pull/12810">12810</a>, PR <a href="https://github.com/python/mypy/pull/12817">12817</a>)
<li>Fix Python 3.11 C API errors (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/12850">12850</a>)
<li>Generate smaller code for casts and some implicit type coercions (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12839">12839</a>)
<li>Optimize calling Python objects with zero or one arguments (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/12862">12862</a>)
<li>Replace integer floor division by a power of two with a shift (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12870">12870</a>)
<li>Add primitives for faster access of <tt>float</tt> and <tt>tuple</tt> type objects (Richard Si, PR <a href="https://github.com/python/mypy/pull/13078">13078</a>)
<li>Fix compile error related to operator assignment in a generator function (Zsolt Dollenstein, PR <a href="https://github.com/python/mypy/pull/13144">13144</a>)
</ul>
<h2>Stubtest Improvements</h2>
<p>Stubtest is a tool for testing that stubs conform to the implementations.
<ul>
<li>Allow ellipsis as default argument (Shantanu, PR <a href="https://github.com/python/mypy/pull/12838">12838</a>)
<li>Support <tt>--version</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/12852">12852</a>)
<li>Check type variables and ParamSpecs (Shantanu, PR <a href="https://github.com/python/mypy/pull/12851">12851</a>)
<li>Add error summary and other output tweaks (KotlinIsland, PR <a href="https://github.com/python/mypy/pull/12855">12855</a>)
</ul>
<h2>Other Notable Fixes and Improvements</h2>
<ul>
<li>Disallow assignments to awaited coroutines that do not return (Shantanu, PR <a href="https://github.com/python/mypy/pull/12853">12853</a>)
<li>Search <tt>sys.path</tt> for <a href="https://peps.python.org/pep-0561/">PEP 561</a> compliant packages (Ashley Whetter, PR <a href="https://github.com/python/mypy/pull/11143">11143</a>)
<li>Treat generators with await as async (Jared Hance, PR <a href="https://github.com/python/mypy/pull/12925">12925</a>)
<li>Fix bug in constraints solver regarding ParamSpec upper bounds (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/12938">12938</a>)
<li>Fix crash on redefined class variable annotated with <tt>Final[<type>]</tt> (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/12951">12951</a>)
<li>Improve handling of overloads with ParamSpec (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/12953">12953</a>)
<li>Don’t suggest installing types packages for some third-party packages that now include types or are obsolete (Shantanu, PR <a href="https://github.com/python/mypy/pull/12959">12959</a>)
<li>Add a short note when an error may be fixed by adding an await (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/12958">12958</a>)
<li>Support unannotated converters for <tt>attr.ib</tt> (t4lz, PR <a href="https://github.com/python/mypy/pull/12815">12815</a>)
<li>Disallow undesirable implicit reexport with a from import (Shantanu, PR <a href="https://github.com/python/mypy/pull/12704">12704</a>)
<li>Fix crash when subclass method has the same name as a type alias (Wesley Collin Wright, PR <a href="https://github.com/python/mypy/pull/13015">13015</a>)
<li>Include end column offset in the mypy AST (bruno messias, PR <a href="https://github.com/python/mypy/pull/12972">12972</a>)
<li>Fix "attribute 'arguments' of 'FuncDef' undefined" incremental crash (Frédéric Perrin, PR <a href="https://github.com/python/mypy/pull/12324">12324</a>)
<li>Fix false positive error on multiple enum base classes (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/12963">12963</a>)
<li>Don't add <tt>__match_args__</tt> for dataclasses and named tuples on Python versions lower than 3.10 (Stanislav K, PR <a href="https://github.com/python/mypy/pull/12503">12503</a>)
<li>Fix crash when overriding partial-type attribute with method (Jake Lishman, PR <a href="https://github.com/python/mypy/pull/12943">12943</a>)
<li>Fix editable installs to current working directory (Shantanu, PR <a href="https://github.com/python/mypy/pull/13161">13161</a>)
</ul>
<h2>Typeshed Updates</h2>
<p>Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see <a href="https://github.com/python/typeshed/commits/master?after=91d6383d9d1ca38157ce46bb498a11347658db1d+0&branch=master&path=stdlib">git log</a> for full list of typeshed changes.
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<ul>
<li>97littleleaf11
<li>Alex Waygood
<li>Ashley Whetter
<li>Bruno Messias
<li>denballakh
<li>Erik Kemperman
<li>Ethan Smith
<li>Fabian Keller
<li>Frédéric Perrin
<li>Hal Blackburn
<li>Ivan Levkivskyi
<li>Jake Lishman
<li>Jared Hance
<li>Jingchen Ye
<li>KotlinIsland
<li>Poruri Sai Rahul
<li>Pranav Rajpal
<li>Ramazan Elsunakev
<li>Richard Si
<li>Shantanu
<li>Stanislav K
<li>t4lz
<li>Wesley Collin Wright
</ul>
<p>I would like to thank Ivan Levkivskyi, in particular, who did most of the preparations for this mypy release. My contribution was mainly to finish and publish this blog post.
<p>We’d also like to thank our employer, Dropbox, for funding the mypy core team.
</body>
</html>
Jukka Lehtosalohttp://www.blogger.com/profile/00122775610277203624noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-17051232789762458422022-05-25T05:33:00.001-07:002022-05-25T07:23:34.778-07:00Mypy 0.960 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 0.960 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type checker for Python. This release includes new features, performance improvements and bug fixes. You can install it as follows:
<pre>
python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Minimal Support for LiteralString</h2>
<p>Recognise <tt>typing.LiteralString</tt> and <tt>typing_extensions.LiteralString</tt> as aliases to <tt>str</tt>.
<p>This does not add proper support for LiteralString, but this allows it to be used in type annotations and stubs. LiteralString will be included in Python 3.11 (<a href="https://peps.python.org/pep-0675/">PEP 675</a>), and it can be used to require that a value is an arbitrary literal string (once fully supported).
<p>This feature was contributed by Shantanu (PR <a href="https://github.com/python/mypy/pull/12559">12559</a>).
<h2>Per-file Timing Stats</h2>
<p>When mypy is run with the (currently hidden) <tt>--timing-stats FILE</tt> option, mypy will record detailed information about time spent type checking each file (microseconds). When profiling mypy runs over a large codebase, it can be useful to know which files are the slowest to type check. We are happy to receive bug reports about unexpectedly slow type checking.
<p>This feature was contributed by Hugues (PR <a href="https://github.com/python/mypy/pull/12639">12639</a>).
<h2>Performance Improvements</h2>
<ul>
<li>Cache type of container literals when possible (Hugues, PR <a href="https://github.com/python/mypy/pull/12707">12707</a>)
<li>Speed up type checking of nested if expressions (Hugues, PR <a href="https://github.com/python/mypy/pull/12700">12700</a>)
<li>Speed up type checking of container literals with tuple entries (Hugues, PR <a href="https://github.com/python/mypy/pull/12706">12706</a>)
<li>Speed up argument count check (Hugues, PR <a href="https://github.com/python/mypy/pull/12703">12703</a>)
<li>Speed up processing large error counts and improve error filtering (Hugues, PR <a href="https://github.com/python/mypy/pull/12631">12631</a>)
</ul>
<h2>Experimental Fast Module Lookup</h2>
<p>Use the new <tt>--fast-module-lookup</tt> to switch to an alternative import resolution implementation that is faster when a large number of folders share a top-level namespace. We’d like to hear if you notice an improvement when using this flag, so that we can potentially prioritize work to enable this by default.
<p>This feature was contributed by Hugues (PR <a href="https://github.com/python/mypy/pull/12616">12616</a>).
<h2>Documentation Updates</h2>
<ul>
<li>Add information about classes and types to “Getting started” (Michael Lee, PR <a href="https://github.com/python/mypy/pull/6557">6557</a>)
<li>Mention <tt>no_type_check</tt> decorator in documentation (Shantanu, PR <a href="https://github.com/python/mypy/pull/12713">12713</a>)
<li>Remove most mentions of type comments from docs (Shantanu, PR <a href="https://github.com/python/mypy/pull/12683">12683</a>)
<li>Use PEP 585 syntax in "The type of class objects" (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/12516">12516</a>)
</ul>
<h2>Improvements to Plugin System</h2>
<ul>
<li>Add a class attribute hook to the plugin system (Danny Weinberg, PR <a href="https://github.com/python/mypy/pull/9881">9881</a>)
<li>Add an alternative class decorator hook that is less error-prone than the old one (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12762">12762</a>)
</ul>
<h2>ParamSpec Improvements</h2>
<ul>
<li>Friendlier errors for ParamSpec (<a href="https://peps.python.org/pep-0612/">PEP</a> <a href="https://peps.python.org/pep-0612/">612</a>) (Shantanu, PR <a href="https://github.com/python/mypy/pull/12832">12832</a>)
<li>Fix ParamSpec crash related to <tt>Any</tt> types (EXPLOSION, PR <a href="https://github.com/python/mypy/pull/12548">12548</a>)
<li>Use <tt>tuple[object, ...]</tt> and <tt>dict[str, object]</tt> as upper bounds for <tt>ParamSpec.args</tt> and <tt>ParamSpec.kwargs</tt> (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/12668">12668</a>)
</ul>
<h2>Fixes to Crashes</h2>
<ul>
<li>Fix crash on invalid Python executable (Pranav Rajpal, PR <a href="https://github.com/python/mypy/pull/12812">12812</a>)
<li>Fix crash on type alias definition inside dataclass declaration (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/12792">12792</a>)
<li>Fix crash related to namedtuple in unannotated function (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12804">12804</a>)
<li>Fix nested namedtuple crash in incremental mode (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12803">12803</a>)
<li>Fix forward references and generic inheritance in <tt>attrs</tt> classes (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12772">12772</a>)
<li>mypyc: Fix TypeError in lambda argument to overloaded function (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12780">12780</a>)
<li>Fix crashes related to <tt>functools.total_ordering</tt> and forward references (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12767">12767</a>)
<li>Fix crashes related to dataclasses and forward references (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12762">12762</a>)
<li>Fix crash on invalid TypedDict definition (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/12741">12741</a>)
<li>Fix crash when using decorator in class scope (dzcode, PR <a href="https://github.com/python/mypy/pull/12724">12724</a>)
</ul>
<h2>Other Notable Fixes and Improvements</h2>
<ul>
<li>Fix type annotation support of dunder methods in stubgen (Fabian Keller, PR <a href="https://github.com/python/mypy/pull/12828">12828</a>)
<li>Fix some value patterns in match statements to be non-exhaustive (Štěpán Horáček, PR <a href="https://github.com/python/mypy/pull/12751">12751</a>)
<li>Generate error when using both abstractmethod and final (Tomoki Nakagawa, PR <a href="https://github.com/python/mypy/pull/12743">12743</a>)
<li>Add more precise error message for Callable annotation (frerikandriessen, PR <a href="https://github.com/python/mypy/pull/12518">12518</a>)
<li>Fix generic inference in functions with <tt>TypeGuard</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11797">11797</a>)
<li>Add check if <tt>python_version</tt> was parsed as float in <tt>pyproject.toml</tt> (Marcel Otoboni, PR <a href="https://github.com/python/mypy/pull/12558">12558</a>)
<li>Fix nested overload merging (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/12607">12607</a>)
<li>stubtest: Generate error if type alias doesn't exist at runtime (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/12608">12608</a>)
<li>Support <tt>typing_extensions.overload</tt> (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/12602">12602</a>)
</ul>
<h2>Typeshed Updates</h2>
<p>Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see <a href="https://github.com/python/typeshed/commits/master?after=a27f15ef0eb12b961d0fb58f8615a3df901a9176+0&branch=master&path=stdlib">git log</a> for full list of typeshed changes.
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<ul>
<li>97littleleaf11
<li>Alex Waygood
<li>Danny Weinberg
<li>EXPLOSION
<li>Ethan Smith
<li>Fabian Keller
<li>Hugues
<li>Ikko Ashimine
<li>Jelle Zijlstra
<li>Marc Mueller
<li>Marcel Otoboni
<li>Max Jones
<li>Michael Lee
<li>Nikita Sobolev
<li>Shantanu
<li>Tomoki Nakagawa
<li>Vincent Vanlaer
<li>dzcode
<li>eggplants
<li>frerikandriessen
<li>Jared Hance
<li>Pranav Rajpal
<li>Štěpán Horáček
</ul>
<p>I’d also like to thank my employer, Dropbox, for funding the mypy core team.</body>
</html>
Jukka Lehtosalohttp://www.blogger.com/profile/00122775610277203624noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-77648396116518842052022-04-27T10:05:00.001-07:002022-04-27T10:08:55.121-07:00Mypy 0.950 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 0.950 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type checker for Python. This release includes new features and bug fixes. You can install it as follows:
<pre>
python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Pinning Third-Party Library Stub Versions</h2>
<p>Recent third-party library stubs available via <tt>types-*</tt> packages (e.g. <tt>types-requests</tt>) are actively using recent typing features that may not be supported by older mypy releases. We recommend that if you pin mypy to a specific version, <i>you should also pin any stub packages to a version no more recent than the mypy release.</i> Otherwise the mypy version you use may silently fall back to <tt>Any</tt> types if it encounters annotation syntax that it can’t process. It’s fine to continue using older versions of stubs when you upgrade mypy.
<p>Note also that recent versions of many third-party stub packages don’t support Python 2 any more. If you are using mypy to type check Python 2 code, it’s important to pin all stub packages to versions that still support Python 2. Generally stub package versions released in Feb 2022 or earlier still support Python 2 (assuming that they supported Python 2 at all).
<h2>New Features: Concatenate and Literals with ParamSpec</h2>
<p>It’s now possible to precisely annotate decorators that add/remove arguments, using <tt>ParamSpec</tt> together with <tt>typing.Concatenate</tt> (Python 3.10 or later) or <tt>typing_extensions.Concatenate</tt>. The decorator in this example provides an implicit <tt>Request</tt> argument to the decorated function:
<pre>
from typing import ParamSpec, TypeVar, Callable, Concatenate
P = ParamSpec("P")
T = TypeVar(T")
def my_decorator(f: Callable[Concatenate[Request, P], T]
) -> Callable[P, T]:
def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
r = current_request()
return f(r, *args, **kwargs)
return wrapper
@my_decorator
def my_func(request: Request, x: int) -> str:
# do something ...
return ...
def func2() -> str:
return my_func(x=2) # OK, the request argument is implicit
</pre>
<p>You can provide the value of a ParamSpec explicitly using the <tt>[T1, …, Tn]</tt> syntax. This example illustrates the use case:
<pre>
from typing import ParamSpec, TypeVar, Generic, Callable
P = ParamSpec("P")
T = TypeVar("T")
class CallCounter(Generic[P, T]):
def __init__(self, fn: Callable[P, T]):
self.fn = fn
self.count = 0
def invoke(self, *args: P.args, **kwargs: P.kwargs) -> T:
self.count += 1
return self.fn(*args, **kwargs)
# The [str] below specifies the value of P (one positional
# argument of type str)
def ensure_n_calls(cc: CallCounter[[str], None],
n: int, arg: str) -> None:
while cc.count < n:
cc.invoke(arg)
</pre>
<p>This experimental support for ParamSpec Concatenate and literals was contributed by EXPLOSION (PR <a href="https://github.com/python/mypy/pull/11847">11847</a>).
<h2>New Feature: Detect Unused Coroutines and Awaitables</h2>
<p>Now mypy will give an error if you forget to await a coroutine:
<pre>
async def log(message: str) -> None:
...
async def do_stuff() -> None:
# Error: Value of type "Coroutine[Any, Any, None]"
# must be used
log("doing stuff") # Oops, no "await"
...
</pre>
<p>If you enable the <tt>unused-awaitable</tt> error code, mypy will also complain about any unused value that supports <tt>__await__</tt>. This is not enabled by default, since this can cause false positives.
<p>This feature was contributed by Jared Hance (PR <a href="https://github.com/python/mypy/pull/12279">12279</a>).
<h2>New Feature: assert_type</h2>
<p>You can now use <tt>typing_extensions.assert_type</tt> to ask mypy to validate that an expression has a specific static type. Mypy will report an error if the inferred type is not as expected:
<pre>
from typing_extensions import assert_type
assert_type([1], list[int]) # OK
# Error: Expression is of type "List[int]", not "List[str]"
assert_type([1], list[str])
</pre>
<p>This can be used to validate that the expected type is inferred by mypy when calling a complex overloaded function, for example. At runtime <tt>assert_type</tt> just returns the first argument and doesn’t perform a runtime type check.
<p>This was contributed by Jelle Zijlstra (PR <a href="https://github.com/python/mypy/pull/12612">12612</a>, PR <a href="https://github.com/python/mypy/pull/12584">12584</a>).
<h2>Mypyc Fixes and Improvements</h2>
<ul>
<li>Fix overflow in <tt>id</tt> built-in (Ekin Dursun, PR <a href="https://github.com/python/mypy/pull/12332">12332</a>)
<li>Simplify generated code for native attribute get (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/11978">11978</a>)
<li>Implement <tt>close</tt> method for generators (Max Shvets, PR <a href="https://github.com/python/mypy/pull/12042">12042</a>)
<li>Use more accurate flags with msvc (KotlinIsland, PR <a href="https://github.com/python/mypy/pull/12468">12468</a>)
<li>Fix potential memory leak with <tt>setdefault()</tt> (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12514">12514</a>)
<li>Make boxed integer constants/literals faster (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12507">12507</a>)
</ul>
<h2>Performance Improvements</h2>
<p>Mypy now type checks somewhat faster, in particular when dealing with enums and unions with many items.
<ul>
<li>Speed up union types (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12541">12541</a>, PR <a href="https://github.com/python/mypy/pull/12519">12519</a>)
<li>Speed up subtype checks (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12540">12540</a>, PR <a href="https://github.com/python/mypy/pull/12538">12538</a>, PR <a href="https://github.com/python/mypy/pull/12536">12536</a>, PR <a href="https://github.com/python/mypy/pull/12539">12539</a>)
<li>Speed up type checking enums (Hugues, PR <a href="https://github.com/python/mypy/pull/12032">12032</a>)
<li>Speed up union types further (Hugues, PR <a href="https://github.com/python/mypy/pull/12630">12630</a>)
</ul>
<h2>Documentation Improvements</h2>
<ul>
<li>Use Furo theme for documentation (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/12348">12348</a>)
<li>Add missing <tt>enable_error_code</tt> to config documentation (Mathieu Kniewallner, PR <a href="https://github.com/python/mypy/pull/12346">12346</a>)
<li>Correct example in “Annotation issues at runtime” (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/12356">12356</a>)
<li>Fix inaccuracy: <tt>NoneType</tt> is exposed in the <tt>types</tt> module on Python 3.10+ (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/12515">12515</a>)
</ul>
<h2>Stubgen Improvements</h2>
<ul>
<li>Fix handling of <tt>Protocol</tt> (citruz, PR <a href="https://github.com/python/mypy/pull/12129">12129</a>)
<li>Use <tt>_typeshed.Incomplete</tt> instead of <tt>typing.Any</tt> (Sebastian Rittau, PR <a href="https://github.com/python/mypy/pull/12449">12449</a>)
<li>Do not consider nested generators (Štěpán Horáček, PR <a href="https://github.com/python/mypy/pull/12463">12463</a>)
<li>Fix behavior for instance variables in C extensions (Shubham SInghal, PR <a href="https://github.com/python/mypy/pull/12524">12524</a>)
</ul>
<h2>Stubtest Improvements</h2>
<ul>
<li>Generate error for read-only property at runtime, but not in stub (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/12291">12291</a>)
<li>Enable verification of <tt>__match_args__</tt> attributes (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/12465">12465</a>)
</ul>
<h2>Other Notable Fixes and Improvements</h2>
<ul>
<li>Use tomllib on Python 3.11 (Shantanu, PR <a href="https://github.com/python/mypy/pull/12305">12305</a>)
<li>Print compilation status with <tt>--version</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/12318">12318</a>)
<li>Fix <tt>__annotations__</tt> being undefined (Niklas Gustafsson, PR <a href="https://github.com/python/mypy/pull/10969">10969</a>)
<li>Add success message for notes-only output (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/12306">12306</a>)
<li>dmypy: Warn instead of failing if report generation is configured (Nate McMaster, PR <a href="https://github.com/python/mypy/pull/10181">10181</a>)
<li>Fix caching of PEP 561 namespace packages with missing submodules (Shantanu, PR <a href="https://github.com/python/mypy/pull/12250">12250</a>)
<li>Fix empty <tt>reveal_locals</tt> output (Cibin Mathew, PR <a href="https://github.com/python/mypy/pull/12400">12400</a>)
<li>Check that async for/with is inside an async function (Štěpán Horáček, PR <a href="https://github.com/python/mypy/pull/12418">12418</a>)
<li>Recognize <tt>Hashable</tt> as a real protocol (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11802">11802</a>)
<li>Remove the * for inferred types from <tt>reveal_type</tt> output (Stanislav K, PR <a href="https://github.com/python/mypy/pull/12459">12459</a>)
<li>Unify a codepath in typevarlike semanal (Jared Hance, PR <a href="https://github.com/python/mypy/pull/12480">12480</a>)
<li>Recognise both <tt>attrs</tt> and <tt>attr</tt> package names (Spencer Brown, PR <a href="https://github.com/python/mypy/pull/12469">12469</a>)
<li>Fix Callable attributes in frozen dataclasses (Jordan Speicher, PR <a href="https://github.com/python/mypy/pull/12383">12383</a>)
<li>Improve checking of <tt>__slots__</tt> (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12531">12531</a>)
<li>Avoid conflicts between type variables defined in different classes (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12590">12590</a>)
<li>Fix <tt>__slots__</tt> and <tt>__deletable__</tt> in incremental mode (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12645">12645</a>)
<li>Fix issue with ParamSpec serialization (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12654">12654</a>)
<li>Fix types of inherited attributes in generic dataclasses (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12656">12656</a>)
</ul>
<h2>Typeshed Updates</h2>
<p>Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see <a href="https://github.com/python/typeshed/commits/master?after=d09689f8115173e3b0b04365f5233164014a7a69+0&branch=master&path=stdlib">git log</a> for full list of typeshed changes.
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<ul>
<li>97littleleaf11
<li>Akuli
<li>Alex Waygood
<li>Chris Rose
<li>Cibin Mathew
<li>citruz
<li>EXPLOSION
<li>Ekin Dursun
<li>Géry Ogam
<li>gresm
<li>Hugues
<li>Ikko Ashimine
<li>Jared Hance
<li>Jelle Zijlstra
<li>Jordan Speicher
<li>Kevin Mai-Husan Chia
<li>KotlinIsland
<li>luzpaz
<li>Marc Mueller
<li>Mathieu Kniewallner
<li>Max Shvets
<li>mixed-source
<li>Nate McMaster
<li>Nikita Sobolev
<li>Niklas Gustafsson
<li>Petter Friberg
<li>Sebastian Rittau
<li>Shantanu
<li>Shubham SInghal
<li>Spencer Brown
<li>Stanislav K
<li>Stanislav Levin
<li>Štěpán Horáček
</ul>
<p>I’d also like to thank my employer, Dropbox, for funding the mypy core team.</body>
</html>
Jukka Lehtosalohttp://www.blogger.com/profile/00122775610277203624noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-5317925955752740792022-03-24T10:29:00.000-07:002022-03-24T10:29:51.905-07:00Mypy 0.942 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 0.942 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type checker for Python. This release includes bug fixes only. You can install it as follows:
<pre>
python3 -m pip install -U mypy
</pre>
<p>You can read the full documentation for this release on <a href="http://mypy.readthedocs.io">Read the Docs</a>.
<h2>Fixes to Regressions</h2>
<ul>
<li>Let overload item have a more general return type than the implementation (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12435">12435</a>)
<li>Fix inheritance false positives with dataclasses/attrs (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12411">12411</a>)
<li>Support overriding dunder attributes in Enum subclass (Petter Friberg, PR <a href="https://github.com/python/mypy/pull/12138">12138</a>)
<li>Fix small conditional overload regression (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/12336">12336</a>)
</ul>
<h2>Other Fixes</h2>
<ul>
<li>Fix issues related to the order of processing in the builtins import cycle (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12431">12431</a>)
<li>Fix crash in match statement if class name is undefined (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12417">12417</a>)
<li>Allow non-final <tt>__match_args__</tt> and overriding (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12415">12415</a>)
</ul>
<p>I’d like to thank my employer, Dropbox, for funding the mypy core team.</body>
</html>Jukka Lehtosalohttp://www.blogger.com/profile/00122775610277203624noreply@blogger.com