tag:blogger.com,1999:blog-3958217975838379332024-03-08T08:16:58.456-08:00The Mypy BlogUpdates about mypy, an optional static type checker for PythonJukka Lehtosalohttp://www.blogger.com/profile/00122775610277203624noreply@blogger.comBlogger86125tag: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.comtag:blogger.com,1999:blog-395821797583837933.post-86215919725806365582022-03-11T07:21:00.002-08:002022-03-11T07:37:23.438-08:00Mypy 0.940 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 0.940 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>Match Statement</h2>
<p>Mypy now has experimental support for type checking match statements introduced in Python 3.10.
<p>Mypy can perform exhaustiveness checking to detect whether a match statement covers all possible values, if the target value has a union type or an enum type:
<pre>
def empty_value(x: int | str) -> str:
match x:
case str():
# Type of "x" is "str" here
return '""'
case int():
# Type of "x" is "int" here
return "0"
# No error about missing return statement (unreachable)
</pre>
<p>Note that exhaustiveness checking is still not generally supported across class hierarchies, since mypy doesn’t support <i>sealed classes</i> with a fixed set of subclasses. You can use an union type or <tt>assert False</tt> as a workaround:
<pre>
class Base(metaclass=ABCMeta): ...
class A(Base): ...
class B(Base): ...
def process(x: A | B) -> bool:
match x:
case A():
...
case B():
...
# Mypy knows that this is unrachable.
def process2(x: Base) -> bool:
match x:
case A():
...
case B():
...
# Use "assert False" to silence error about missing import,
# since mypy can't prove that code is unreachable.
assert False
</pre>
<p>You can also use an “assert never” function for more explicit exhaustiveness checks with match statements, as discussed in the <a href="https://mypy.readthedocs.io/en/stable/literal_types.html#exhaustiveness-checking">documentation</a>.
<p>This feature was contributed by Adrian Freund (PR <a href="https://github.com/python/mypy/pull/12267">12267</a>, PR <a href="https://github.com/python/mypy/pull/10191">10191</a>), with additional updates by Jukka Lehtosalo.
<h2>Python 2 End-of-Life Schedule</h2>
<p>After this release, Python 2 support is in <i>feature freeze</i>. Mypy won’t add new features or fixes specific to type checking Python 2 code, expect for fixes of significant regressions.
<p>Mypy will drop Python 2 support in the second half of 2022.
<p><b>Important note:</b> Since typeshed is in the process of removing Python 2 specific stubs, you should pin all installed typeshed stub packages for third-party libraries to a version from Feb 2022 or earlier if you want to type check Python 2 code.
<h2>Miscellaneous New Features</h2>
<ul>
<li>Add support for conditionally defined overloads (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/10712">10712</a>)
<li>Give "as" variables in with statements separate scopes when it is safe to do so (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12254">12254</a>)
<li>Add an optional error code <tt>ignore-without-code</tt> to require ignore comments to have error codes (Peter Law, PR <a href="https://github.com/python/mypy/pull/11633">11633</a>)
<li>Add support for <tt>typing.Never</tt> and <tt>typing_extensions.Never</tt> as alternative spellings of <tt>NoReturn</tt> (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/12153">12153</a>)
<li>Add support for <tt>typing.reveal_type</tt> (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/12117">12117</a>)
<li>Support universal2 macOS wheels (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10651">10651</a>)
<li>Add <tt>match_args</tt> support to <tt>attr.s()</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/12111">12111</a>)
</ul>
<h2>Enum Improvements</h2>
<ul>
<li>Check <tt>Enum</tt> definition for invalid base classes (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/12026">12026</a>)
<li>Understand the self-destructing nature of <tt>Enum._ignore_</tt> (Kenny Stauffer, PR <a href="https://github.com/python/mypy/pull/12128">12128</a>)
<li>Add <tt>StrEnum</tt> support for Python 3.11 (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/12035">12035</a>)
<li>Make enum values final (joey-laminar, PR <a href="https://github.com/python/mypy/pull/11962">11962</a>)
<li>Improve <tt>final</tt> detection for <tt>Enum</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11984">11984</a>)
<li>Fix <tt>Enum</tt> final properties and writable special members (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11945">11945</a>)
<li>Enum now accepts String literals and final values as 2nd argument (Vincent Perez, PR <a href="https://github.com/python/mypy/pull/8664">8664</a>)
<li>Fix false positive about member name reuse in enum (Max Rossmannek, PR <a href="https://github.com/python/mypy/pull/11972">11972</a>)
<li>Fix enum inheritance regression (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/12260">12260</a>)
</ul>
<h2>Mypyc Fixes and Improvements</h2>
<ul>
<li>Use <tt>Py_TYPE</tt> and <tt>Py_IsNone</tt> (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/12233">12233</a>)
<li>Implement additional internal consistency checks (Jared Hance, PR <a href="https://github.com/python/mypy/pull/12191">12191</a>)
<li>Raise AttributeError also for non-refcounted types (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/11940">11940</a>)
<li>Fix invalid unlikely() in certain rare branches (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/11939">11939</a>)
<li>Skip no-op super calls to <tt>object.__init__()</tt> (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/11938">11938</a>)
<li>Use latest pythoncapi_compat (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/12188">12188</a>)
<li>Add helpful message to assert (Joshua Cannon, PR <a href="https://github.com/python/mypy/pull/12119">12119</a>)
</ul>
<h2>Documentation Updates</h2>
<ul>
<li>Add documentations about <tt>Enum</tt> types (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11805">11805</a>)
<li>Update <tt>Enum</tt> documentation (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/12238">12238</a>)
<li>Improve documentation of <tt>allow_redefinition</tt> (KotlinIsland, PR <a href="https://github.com/python/mypy/pull/11951">11951</a>)
<li>Fix intelligent indexing example (Chris Keefe, PR <a href="https://github.com/python/mypy/pull/11973">11973</a>)
<li>Explain generic <tt>Protocol[T1, T2, ...]</tt> shorthand (Matt Bogosian, PR <a href="https://github.com/python/mypy/pull/12047">12047</a>)
<li>Clarify that stub-only packages need to be installed (Gustav Gränsbo, PR <a href="https://github.com/python/mypy/pull/9958">9958</a>)
<li>Small documentation improvements for conditional overloads (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/12283">12283</a>)
</ul>
<h2>Improved Error Messages</h2>
<ul>
<li>Improve the "Argument must be a mapping" error message (Purna Chandra Mansingh, PR <a href="https://github.com/python/mypy/pull/12222">12222</a>)
<li>Coalesce Literals when printing unions (Marti Raudsepp, PR <a href="https://github.com/python/mypy/pull/12205">12205</a>)
<li>Suggest <tt>typing.Callable</tt> when using <tt>callable</tt> as type (Tuomas Siipola, PR <a href="https://github.com/python/mypy/pull/12204">12204</a>)
<li>Suggest <tt>typing.Any</tt> when using <tt>any</tt> as type (Tuomas Siipola, PR <a href="https://github.com/python/mypy/pull/12185">12185</a>)
<li>Add note about wrong error code in <tt>type: ignore</tt> (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12067">12067</a>)
<li>Add <tt>no-overload-impl</tt> error code (Brian Phillips, PR <a href="https://github.com/python/mypy/pull/11944">11944</a>)
<li>Display ellipsis when formatting variadic <tt>tuple[T, ...]</tt> (Marti Raudsepp, PR <a href="https://github.com/python/mypy/pull/11857">11857</a>)
<li>Deduplicate error codes for <tt>ignore-without-code</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/12194">12194</a>)
<li>Tweak <tt>ignore-without-code</tt> error message (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/12216">12216</a>)
<li>Mention common resolutions for build errors (Shantanu, PR <a href="https://github.com/python/mypy/pull/12154">12154</a>)
</ul>
<h2>Stubtest Improvements</h2>
<ul>
<li>Ignore more dunder positional-only errors (Shantanu, PR <a href="https://github.com/python/mypy/pull/12294">12294</a>)
<li>Fix wrong assumption about relative path (Stanislav Levin, PR <a href="https://github.com/python/mypy/pull/12282">12282</a>)
<li>Catch more getattr errors (Shantanu, PR <a href="https://github.com/python/mypy/pull/12219">12219</a>)
<li>Error if module level dunder is missing, housekeeping (Shantanu, PR <a href="https://github.com/python/mypy/pull/12217">12217</a>)
<li>Ignore <tt>__main__</tt> module (Shantanu, PR <a href="https://github.com/python/mypy/pull/12218">12218</a>)
<li>Error if a dunder method is missing from a stub (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/12203">12203</a>)
<li>Error if a function is async at runtime but not in the stub (and vice versa) (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/12212">12212</a>)
<li>Do not error if a stub is async, but runtime is not (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/12234">12234</a>)
<li>Error if a class should be decorated with <tt>@final</tt> (Akuli, PR <a href="https://github.com/python/mypy/pull/12091">12091</a>)
<li>Use VERSIONS for submodules (Shantanu, PR <a href="https://github.com/python/mypy/pull/12083">12083</a>)
<li>Treat dicts as a subtype of typeddict (Shantanu, PR <a href="https://github.com/python/mypy/pull/12040">12040</a>)
<li>Ignore more exceptions in stubtest (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/11946">11946</a>)
</ul>
<h2>Other Notable Fixes and Improvements</h2>
<ul>
<li>Fix non-default keyword-only argument positioning in stubgen (Štěpán Horáček, PR <a href="https://github.com/python/mypy/pull/12303">12303</a>)
<li>Remove orjson stubs from default list (Shantanu, PR <a href="https://github.com/python/mypy/pull/12264">12264</a>)
<li>Use <tt>__truediv__</tt> for Python 2 with <tt>__future__</tt> import (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11787">11787</a>)
<li>Fix Python 2 compatibility issue (Shantanu, PR <a href="https://github.com/python/mypy/pull/12244">12244</a>)
<li>Use type variable bound to infer constraints (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12230">12230</a>)
<li>Handle <tt>raise Exception(), None</tt> on Python 2.7 (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11786">11786</a>)
<li>Fix inference of protocol against overloaded function (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12227">12227</a>)
<li>Fix an <tt>issubclass</tt> failure for protocols with overloaded methods (Bas van Beek, PR <a href="https://github.com/python/mypy/pull/9904">9904</a>)
<li>Fix crashes in class scoped imports (PR <a href="https://github.com/python/mypy/pull/12199">12199</a>, PR <a href="https://github.com/python/mypy/pull/12023">12023</a>) (Shantanu)
<li>Fix use of TypeAlias from aliased imports (Shantanu, PR <a href="https://github.com/python/mypy/pull/12180">12180</a>)
<li>Delete <tt>open</tt> plugin (Shantanu, PR <a href="https://github.com/python/mypy/pull/9275">9275</a>)
<li>Read pyproject.toml with correct encoding on Windows (Dominic Davis-Foster, PR <a href="https://github.com/python/mypy/pull/12105">12105</a>)
<li>Fix issue with implicit type aliases in import cycles (but only for stubs) (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/11915">11915</a>)
<li>Forbid extra <tt>ParamSpec</tt> arguments (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/12024">12024</a>)
<li>Fix crash involving explicit any flag and <tt>Required</tt> (Mehdi Drissi, PR <a href="https://github.com/python/mypy/pull/12039">12039</a>)
<li>Fix join of <tt>Any</tt> against a union type (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12068">12068</a>)
<li>Simplify unions when erasing last known values (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/12064">12064</a>)
<li>Fix crash with yield in comprehension (Alexandre Bouayad, PR <a href="https://github.com/python/mypy/pull/12048">12048</a>)
<li>Fix handling of <tt>NoReturn</tt> in union return types (Jannic Warken, PR <a href="https://github.com/python/mypy/pull/11996">11996</a>)
<li>Fix <tt>__init__</tt> in dataclasses inheriting from <tt>Any</tt> (joey-laminar, PR <a href="https://github.com/python/mypy/pull/11966">11966</a>)
<li>Narrow NamedTuple to bool correctly when <tt>__bool__</tt> is defined (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11822">11822</a>)
<li>Improve type of <tt>__attrs_attrs__</tt> in attrs classes (Tin Tvrtković, PR <a href="https://github.com/python/mypy/pull/11794">11794</a>)
<li>Install dependencies needed for reports via <tt>pip install mypy[reports]</tt> (James Braza, PR <a href="https://github.com/python/mypy/pull/11777">11777</a>)
<li>Consider import * to be an explicit re-export (Shantanu, PR <a href="https://github.com/python/mypy/pull/11867">11867</a>)
<li>Fix <tt>--no-implicit-reexport</tt> inconsistency (Shantanu, PR <a href="https://github.com/python/mypy/pull/11707">11707</a>)
<li>Fix crash if "_" is in builtins (StefanM-TT, PR <a href="https://github.com/python/mypy/pull/11811">11811</a>)
<li>Fixes crash on subclassing <tt>Annotated</tt> without args (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11814">11814</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=9116b2928d63632cb9c9526b18d1ffafaf5bafa4+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>Adrian Freund
<li>Akuli
<li>Alex Waygood
<li>Alexandre Bouayad
<li>Anthony Sottile
<li>Bas van Beek
<li>Brian Phillips
<li>Chris Keefe
<li>Dominic Davis-Foster
<li>Gustav Gränsbo
<li>James Braza
<li>Jannic Warken
<li>Jared Hance
<li>Jelle Zijlstra
<li>joey-laminar
<li>Joshua Cannon
<li>Kenny Stauffer
<li>KotlinIsland
<li>Marc Mueller
<li>Mark Bell
<li>Marti Raudsepp
<li>Matt Bogosian
<li>Max Rossmannek
<li>Mehdi Drissi
<li>Michael R. Crusoe
<li>Nikita Sobolev
<li>Oliver Newman
<li>Peter Law
<li>Purna Chandra Mansingh
<li>Shantanu
<li>Stanislav Levin
<li>StefanM-TT
<li>Tin Tvrtković
<li>Tuomas Siipola
<li>Vincent Perez
<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-805376737931887572022-01-07T09:08:00.000-08:002022-01-07T09:08:10.442-08:00Mypy 0.931 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 0.931 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 and fixes to regressions 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>Fix mypyc binary wheel (Michael R. Crusoe, PR <a href="https://github.com/python/mypy/pull/11862">11862</a>)
<li>Revert to treating multi-line strings as a single value for <tt>exclude</tt> in TOML files (Matt Bogosian, PR <a href="https://github.com/python/mypy/pull/11828">11828</a>)
<li>Revert to treating <tt>exclude</tt> in <tt>.ini</tt> as a single value (Matt Bogosian, PR <a href="https://github.com/python/mypy/pull/11881">11881</a>)
<li>Fix <tt>__slots__</tt> regression (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11824">11824</a>)
<li>Fix regression with <tt>__module__</tt> and similar non-final Enum attributes (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11823">11823</a>)
<li>Fix regression when a <tt>contextmanager</tt> yields a generic function (Anthony Sottile, PR <a href="https://github.com/python/mypy/pull/11870">11870</a>)
<li>Fix <tt>__reduce__</tt> regression (Shantanu, PR <a href="https://github.com/python/mypy/pull/11866">11866</a>)
<li>Fix <tt>NoReturn</tt> type aliases (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11912">11912</a>)
<li>Fix regression in <tt>None</tt> handling with <tt>--no-strict-optional</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11717">11717</a>)
<li>Fix crash related to generics (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11924">11924</a>)
<li>Restore removed <tt>builtin_type()</tt> plugin API method (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/11932">11932</a>)
</ul>
<h2>Other Fixes</h2>
<ul>
<li>Always allow the use of <tt>type[T]</tt> in stubs (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11863">11863</a>)
<li>Fix PEP 585 type aliases in stubs (Shantanu, PR <a href="https://github.com/python/mypy/pull/11918">11918</a>)
<li>Fix bug with literal types in stubtest (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11931">11931</a>)
</ul>
<p>We’d 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-1399548511275611472021-12-22T09:45:00.001-08:002022-01-05T08:53:18.369-08:00Mypy 0.930 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 0.930 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>New Feature: Explicit Type Aliases (PEP 613)</h2>
<p>You can now explicitly mark an assignment as a type alias, by using <tt>typing.TypeAlias</tt>:
<pre>
# On Python 3.9 and earlier, use "from typing_extensions ..."
from typing import TypeAlias
A: TypeAlias = int | str
</pre>
<p>For more context, see the <a href="https://mypy.readthedocs.io/en/latest/kinds_of_types.html#type-aliases">docs</a> or <a href="https://www.python.org/dev/peps/pep-0613/">PEP 613</a>.
<p>This was contributed by Shantanu in PR <a href="https://github.com/python/mypy/pull/11305">11305</a>.
<h2>New Feature: NotRequired in TypedDicts</h2>
<p>You can now define individual TypedDict items as non-required by using <tt>typing_extensions.NotRequired</tt>. Previously this could only be configured at TypedDict level (by using <tt>total=</tt>). Example:
<pre>
from typing import TypedDict
from typing_extensions import NotRequired
class D(TypedDict):
x: str
y: NotRequired[int]
a: D = {"x": "value"} # OK
b: D = {"x": "value", y: 0} # OK
c: D = {} # Error: "x" is required
</pre>
<p>You can also use <tt>typing_extensions.Required</tt> to mark an item as required in a non-total TypedDict.
<p>For more information, see the <a href="https://www.python.org/dev/peps/pep-0655/">draft PEP 655</a>.
<p>This was contributed by David Foster in PR <a href="https://github.com/python/mypy/pull/10370">10370</a>.
<h2>New Feature: ParamSpec (Experimental)</h2>
<p>Mypy now partially support <tt>ParamSpec</tt>, which was introduced in Python 3.10. This makes it possible to define type variables that range over the parameter specification of a callable type. In particular, it allows giving precise types for some decorators that change the return type of the decorated function.
<p>Here’s an example copied (and slightly modified) from <a href="https://www.python.org/dev/peps/pep-0612/">PEP 612</a>:
<pre>
from typing import Awaitable, Callable, ParamSpec, TypeVar
P = ParamSpec("P")
R = TypeVar("R")
def add_logging(f: Callable[P, R]) -> Callable[P, Awaitable[R]]:
async def inner(*args: P.args, **kwargs: P.kwargs) -> R:
await log_to_database()
return f(*args, **kwargs)
return inner
@add_logging
def takes_int_str(x: int, y: str) -> int:
return x + 7
await takes_int_str(1, "A") # Accepted
await takes_int_str("B", 2) # Rejected
</pre>
<p>See <a href="https://docs.python.org/3/library/typing.html#typing.ParamSpec">Python documentation</a> and <a href="https://www.python.org/dev/peps/pep-0612/">PEP 612</a> for additional details. Note that <tt>typing.Concatenate</tt> and some other use cases are still not supported.
<p>Support for semantic analysis of ParamSpec was contributed by Shantanu. Jukka Lehtosalo implemented type checking of ParamSpec types. Additional fixes were contributed by Nikita Sobolev.
<h2>Miscellaneous New Features</h2>
<ul>
<li>Define a GitHub Action that makes it easier to run mypy in GitHub CI workflows (Elvis Pranskevichus, PR <a href="https://github.com/python/mypy/pull/11320">11320</a>)
<li>Allow mypy to run self check on PyPy 3.8 beta (Ethan Smith, PR <a href="https://github.com/python/mypy/pull/11350">11350</a>)
<li>Check that enum values are unique (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11267">11267</a>)
<li>Make enum classess with values implicitly final (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11247">11247</a>)
<li>Make enum members implicitly final (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/10852">10852</a>)
<li>Allow <tt>NamedTuple</tt> to be used as a type that accepts all named tuples, as an experimental extension (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11162">11162</a>)
<li>Allow booleans to be narrowed to literal types (Ethan Leba, PR <a href="https://github.com/python/mypy/pull/10389">10389</a>)
<li>Add <tt>slots=True</tt> support for <tt>@dataclass</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11483">11483</a>)
<li>Add <tt>slots=True</tt> support for <tt>@attr.s</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11489">11489</a>)
<li>Support the <tt>typing_extensions.OrderedDict</tt> alias (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11533">11533</a>)
</ul>
<h2>Usability and Documentation Improvements</h2>
<ul>
<li>Add better <tt>NamedTuple</tt> error messages (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11127">11127</a>)
<li>Show all overloads in error message (Akuli, PR <a href="https://github.com/python/mypy/pull/9177">9177</a>)
<li>Fix error message for <tt>dataclasses.field</tt> with positional argument (Hiroshi Ogawa, PR <a href="https://github.com/python/mypy/pull/11180">11180</a>)
<li>Fix error message for f-string and <tt>str-bytes-safe</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11139">11139</a>)
<li>Add documentation for <tt>type: ignore</tt> (Tushar Sadhwani, PR <a href="https://github.com/python/mypy/pull/11358">11358</a>)
<li>Support <tt>--exclude</tt> more than once on command line (Nipunn Koorapati, PR <a href="https://github.com/python/mypy/pull/11329">11329</a>)
<li>Use <tt>list[int]</tt> instead of <tt>List[int]</tt> in documentation (PR <a href="https://github.com/python/mypy/pull/11377">11377</a>, PR <a href="https://github.com/python/mypy/pull/11450">11450</a>) (Nick Crews)
<li>Remove <tt>builtins.</tt> from error messages (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/11522">11522</a>)
<li>Document explicit type aliases (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11800">11800</a>)
<li>Improve documentation of annotating generator functions (Alex Waygood, PR <a href="https://github.com/python/mypy/pull/11623">11623</a>)
<li>Improve error message for nested TypedDict (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/11658">11658</a>)
<li>Exit gracefully on KeyboardInterrupt (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/10725">10725</a>)
</ul>
<h2>Optimizations</h2>
<p>This release includes some optimizations that make mypy a bit faster (in addition to mypyc performance improvements discussed below):
<ul>
<li>Enable <tt>--fast-exit</tt> by default to speed up mypy (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/11541">11541</a>)
<li>Only read the stdlib versions dictionary once per run (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/11542">11542</a>)
<li>Optimize commonly used function (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/11543">11543</a>)
<li>Minor optimization/cleanup (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/11544">11544</a>)
<li>Reduce the number of executed local imports (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/11545">11545</a>)
</ul>
<h2>Mypyc Fixes and Improvements</h2>
<ul>
<li>Add missing type coercions (Jared Hance, PR <a href="https://github.com/python/mypy/pull/11176">11176</a>)
<li>Support <tt>--allow-redefinition</tt> (Jared Hance, PR <a href="https://github.com/python/mypy/pull/11175">11175</a>)
<li>Constant fold integer operations and string concatenation (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/11194">11194</a>)
<li>Use optimized implementation for <tt>builtins.sum</tt> (Sara Sinback and 97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10268">10268</a>)
<li>Move mypyc to console_scripts to fix running on Windows 10 (谭九鼎, PR <a href="https://github.com/python/mypy/pull/11494">11494</a>)
<li>Make <tt>min(x, y)</tt> faster(Chetan Khanna and 97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10265">10265</a>)
<li>Make <tt>max(x, y)</tt> faster (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/11530">11530</a>)
<li>Speed up reference counting operations by inlining them in commonly executed blocks (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/11540">11540</a>)
<li>Add support for attrs classes (Chad Dombrova, PR <a href="https://github.com/python/mypy/pull/11328">11328</a>)
<li>Port mypyc to Python 3.11 (Victor Stinner, PR <a href="https://github.com/python/mypy/pull/11652">11652</a>)
<li>Reduce the amount of debug information included in compiled extension modules (Nehal J Wani, PR <a href="https://github.com/python/mypy/pull/11526">11526</a>)
</ul>
<h2>Other Notable Fixes and Improvements</h2>
<ul>
<li>Fix semantic analysis of assignment expressions (Shantanu, PR <a href="https://github.com/python/mypy/pull/11153">11153</a>)
<li>Fixes mypy crash on protocol with contravariant variable (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11135">11135</a>)
<li>Warn about unused ignores when not all specified error codes are used (Hiroshi Ogawa, PR <a href="https://github.com/python/mypy/pull/11178">11178</a>)
<li>Improve type narrowing for walrus operator in conditional statements (Shantanu, PR <a href="https://github.com/python/mypy/pull/11202">11202</a>)
<li>Fix literal type compatibility checking special case (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11236">11236</a>)
<li>Rename API method <tt>builtin_type</tt> to <tt>named_type</tt> (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/11224">11224</a>)
<li>Fix narrowing information not propagated in assignment and boolean expressions (Ran Benita, PR <a href="https://github.com/python/mypy/pull/11207">11207</a>)
<li>Fix narrowing of a nested union of TypedDicts (Ran Benita, PR <a href="https://github.com/python/mypy/pull/11204">11204</a>)
<li>Fix case mismatching modules during namespace package search (Nipunn Koorapati, PR <a href="https://github.com/python/mypy/pull/11261">11261</a>)
<li>Disallow invalid identifiers from getting implicit bazel <tt>__init__.py</tt> (Nipunn Koorapati, PR <a href="https://github.com/python/mypy/pull/11268">11268</a>)
<li>Don’t type check lambdas nested in unchecked functions (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11213">11213</a>)
<li>Update <tt>None.__bool__</tt> to return <tt>Literal[False]</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11290">11290</a>)
<li>Relax type checking of <tt>%</tt> formatting when the right operand is an iterable (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/11319">11319</a>)
<li>Fix crash with namespace packages when generating html reports (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11338">11338</a>)
<li>Allow slice syntax in <tt>Annotated</tt> types (Zac Hatfield-Dodds, PR <a href="https://github.com/python/mypy/pull/11345">11345</a>)
<li>Show warning if <tt>self</tt> / <tt>cls</tt> argument is missing (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11317">11317</a>)
<li>Improve subtype checking of TypeGuard types (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11314">11314</a>)
<li>Fix type narrowing for overlaping runtime types (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11273">11273</a>)
<li>Do not use TypeGuard context for lambda (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11417">11417</a>)
<li>Check reachability in module bodies (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11361">11361</a>)
<li>Check that <tt>__new__</tt> in a metaclass returns a subtype of <tt>type</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11420">11420</a>)
<li>Improve support of <tt>contextlib.asynccontextmanager</tt> (Barnaby Shearer, PR <a href="https://github.com/python/mypy/pull/11352">11352</a>)
<li>Discard deprecated <tt>builtin_type</tt> (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/11343">11343</a>)
<li>Don't look in user site packages when using a virtual env (Dimitri Merejkowsky, PR <a href="https://github.com/python/mypy/pull/11444">11444</a>)
<li>Update stubgen to preserve string literals in annotations (Imad Eddine Rezgui, PR <a href="https://github.com/python/mypy/pull/11292">11292</a>)
<li>Fix issue with exporting names in the presence of <tt>__getattr__</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/11411">11411</a>)
<li>Reject duplicate bases when defining TypedDict (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/11485">11485</a>)
<li>Fix type inference for index expression with a bounded TypeVar (Ilya Labun, PR <a href="https://github.com/python/mypy/pull/11434">11434</a>)
<li>Fix <tt>get_dynamic_class_hook</tt> in some scenarios (Jade Lin, PR <a href="https://github.com/python/mypy/pull/10904">10904</a>)
<li>Check <tt>print >></tt> properly (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11576">11576</a>)
<li>Correctly handle <tt>cls</tt> in protocol classmethod (Ilia Novoselov, PR <a href="https://github.com/python/mypy/pull/11119">11119</a>)
<li>Use current Python version, rather than hardcoding 3.6, in stubgen (Shantanu, PR <a href="https://github.com/python/mypy/pull/10907">10907</a>)
<li>Don't use <tt>ModuleType.__getattr__</tt> if we know module symbols (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/11597">11597</a>)
<li>Fix strict equality when using the latest typeshed (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/11599">11599</a>)
<li>Make sure <tt>ClassVar</tt> does not contain type variables (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11585">11585</a>)
<li>Allow overriding attributes with methods (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11561">11561</a>)
<li>Don’t generate an error for PEP 593 <tt>Annotated</tt> with a string literal second argument (Seth Yastrov, PR <a href="https://github.com/python/mypy/pull/10777">10777</a>)
<li>Install types to the correct environment (Konstantin Weddige, PR <a href="https://github.com/python/mypy/pull/11457">11457</a>)
<li>Support decorators in additional contexts (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11150">11150</a>)
<li>Fix crash involving unreachable binary operations (Shantanu, PR <a href="https://github.com/python/mypy/pull/11680">11680</a>)
<li>Fix <tt>None</tt> assignments with mypy daemon cache (Christian Bundy, PR <a href="https://github.com/python/mypy/pull/11574">11574</a>)
<li>Handle <tt>OSError</tt> when accessing the mtime of a mypy cache file (Zac Hatfield-Dodds, PR <a href="https://github.com/python/mypy/pull/11718">11718</a>)
<li>Special case some special <tt>Enum</tt> properties to be non-final (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11713">11713</a>)
<li>Fix crash involving undefined cyclic <tt>import *</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/11681">11681</a>)
<li>Remove incorrect assumption about file system case sensitivity (Shantanu, PR <a href="https://github.com/python/mypy/pull/11708">11708</a>)
<li>Fix compatibility of <tt>bool</tt> and <tt>Literal[True, False]</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11709">11709</a>)
<li>Allow subclassing enums with annotations and no values (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11579">11579</a>)
</ul>
<h2>Typeshed Updates</h2>
<p>Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library. Please see <a href="https://github.com/python/typeshed/commits/master?after=2445eddb4b67fdaa58ec7c2113ff1542021a6206+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>Abdul Rehaman
<li>Akuli
<li>Alex Waygood
<li>Barnaby Shearer
<li>Chad Dombrova
<li>Chetan Khanna
<li>Christian Bundy
<li>Daniel Mendelsohn
<li>David Foster
<li>DetachHead
<li>Dimitri Merejkowsky
<li>Elisha Hollander
<li>Elvis Pranskevichus
<li>Ethan Leba
<li>Ethan Smith
<li>Hiroshi Ogawa
<li>Ilia Novoselov
<li>Ilya Labun
<li>Imad Eddine Rezgui
<li>Infinil
<li>Jared Hance
<li>Ken Jin
<li>Konstantin Weddige
<li>KotlinIsland
<li>Louis Sautier
<li>luzpaz
<li>Marc Mueller
<li>Nehal J Wani
<li>Neil Girdhar
<li>Nick Crews
<li>Nikita Sobolev
<li>Nipunn Koorapati
<li>Noé Rubinstein
<li>parthaxntn
<li>Peter Law
<li>pranavrajpal
<li>Ran Benita
<li>Sara Sinback
<li>Sebastian Rittau
<li>Seth Yastrov
<li>Shantanu
<li>Taneli Hukkinen
<li>Tushar Sadhwani
<li>Victor Stinner
<li>William Woodruff
<li>Zac Hatfield-Dodds
<li>林玮 (Jade Lin)
<li>谭九鼎
</ul>
<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-8910161289919118092021-12-21T11:18:00.001-08:002021-12-21T11:18:24.310-08:00Mypy 0.921 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 0.921 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>Bug Fixes Included in This Release</h2>
<ul>
<li>Fix regression in <tt>PathLike</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/11785">11785</a>)
<li>Allow calling a function with name <tt>_</tt> (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/11810">11810</a>)
<li>Fix signature in <tt>curses</tt> and corresponding <tt>dmypy</tt> bug (Shantanu, PR <a href="https://github.com/python/mypy/pull/11785">11785</a>)
</ul>
<p>We’d like to thank our employer, Dropbox, for funding the mypy core team.</body>Ivanhttp://www.blogger.com/profile/06171376418884900509noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-16705892247823225972021-12-15T15:55:00.001-08:002021-12-16T05:04:40.656-08:00Mypy 0.920 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 0.920 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>Making a Variable Optional in an Else Block</h2>
<p>Now mypy allows more general conditionally defined variables with optional types. Previously mypy allowed this only if a <tt>None</tt> assignment happened first. Now this is also supported:
<pre>
def func() -> int: ...
if test():
x = func()
else:
x = None # Ok, 'x' has type int | None
</pre>
<p>Implemented by Michael J. Sullivan in PR <a href="https://github.com/python/mypy/pull/11002">11002</a>.
<h2>Type Checking <tt>__slots__</tt> Assignment</h2>
<p>For classes that define the special <tt>__slots__</tt> attribute, mypy will now report an error on assigning to attributes that are not found in the slots definitions (this matches <a href="https://docs.python.org/3/reference/datamodel.html#slots">runtime semantics</a>). Example:
<pre>
class SuperClass:
__slots__ = ("a",)
class SubClass(SuperClass):
__slots__ = ("b",)
def __init__(self) -> None:
self.a = 1 # OK
self.b = 2 # OK
self.c = 3 # Error, previously mypy allowed this.
</pre>
<p>Note that this feature does not work for dynamically computed slots. Implemented by Nikita Sobolev in PR <a href="https://github.com/python/mypy/pull/10864">10864</a>.
<h2>Partial Python 3.10 Support</h2>
<p>We now ship binary wheels for Python 3.10 and mypy supports the new Python 3.10 union type syntax:
<ul>
<li><tt>X | Y</tt> is the new syntax for <tt>Union[X, Y]</tt>
<li><tt>X | None</tt> is the new syntax for <tt>Optional[X]</tt>.
</ul>
<p>Some new features, including the match statement, <tt>ParamSpec</tt> and <tt>TypeAlias</tt> are not supported yet.
<h2>Python 3.5 Is No Longer Supported</h2>
<p>Python 3.5 reached its end of life more than a year ago. Its support was deprecated in mypy 0.910 and it is no longer supported in mypy 0.920.
<h2>Efficient String and Bytes Formatting in Mypyc</h2>
<p>Most string and bytes formatting methods now use fast C-level logic when compiled with mypyc. This includes <tt>%</tt> formatting, the <tt>format()</tt> method, and f-strings. This was implemented by 97littleleaf11 as part of a Google Summer of Code project.
<h2>Work Towards <tt>singledispatch</tt> Support</h2>
<p>Mypy and mypyc now have experimental support for <tt>functools.singledispatch</tt>. Here is a simple example:
<pre>
from functools import singledispatch
class Expression: pass
class Literal(Expression):
def __init__(self, value: float) -> None:
self.value = value
class Add(Expression):
def __init__(self, left: Expression, right: Expression) -> None:
self.left = left
self.right = right
@singledispatch
def evaluate(e: Expression) -> float:
assert False, f"unsupported expression: {e}"
@evaluate.register
def _(e: Literal) -> float:
return e.value
@evaluate.register
def _(e: Add) -> float:
return evaluate(e.left) + evaluate(e.right)
print(evaluate(Literal(2)))
print(evaluate(Add(Literal(3), Literal(5))))
</pre>
<p>The signature of the initial function variant handles the generic case and describes the external signature of the singledispatch function.
<p>This was implemented Pranav Rajpal as part of a Google Summer of Code project.
<h2>Stubgen Improvements</h2>
<ul>
<li>Add support for <tt>yield</tt> statements in stubgen (Sebastian Rittau, PR <a href="https://github.com/python/mypy/pull/10745">10745</a>)
<li>Handle commas in namedtuple field definition in stubgen (Vanessa Ung, PR <a href="https://github.com/python/mypy/pull/10828">10828</a>)
</ul>
<h2>Other Notable Fixes and Improvements</h2>
<ul>
<li>Allow plugin signature hooks to return <tt>FunctionLike</tt> (to support overloads) (pranavrajpal, PR <a href="https://github.com/python/mypy/pull/10717">10717</a>)
<li>Narrow type with type variable when the upper bound is a subtype of current type (ethframe, PR <a href="https://github.com/python/mypy/pull/10658">10658</a>)
<li>Make <tt>--cache-fine-grained</tt> imply <tt>--local-partial-types</tt> (Michael J. Sullivan, PR <a href="https://github.com/python/mypy/pull/10737">10737</a>)
<li>Support new union syntax in stubs independent of target Python version and in runtime context (PR <a href="https://github.com/python/mypy/pull/10770">10770</a>, PR <a href="https://github.com/python/mypy/pull/10771">10771</a>) (Jukka Lehtosalo)
<li>Support new union type syntax with <tt>isinstance()</tt> (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/10775">10775</a>)
<li>Better message if method is incompatible with base class (Anmol Takiar, PR <a href="https://github.com/python/mypy/pull/10572">10572</a>)
<li>Allow redefinition of underscore functions (named <tt>'</tt><tt>_</tt><tt>'</tt>) (pranavrajpal, PR <a href="https://github.com/python/mypy/pull/10811">10811</a>)
<li>Properly track positional-only arguments for unannotated functions (Michael J. Sullivan, PR <a href="https://github.com/python/mypy/pull/10802">10802</a>)
<li>Fixes to type checking <tt>%c</tt> string and bytes interpolation (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10869">10869</a>)
<li>Use better error message for <tt>%c</tt> interpolation (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10875">10875</a>)
<li>Skip overlapping overload checks in ignored files (Shantanu, PR <a href="https://github.com/python/mypy/pull/10922">10922</a>)
<li>Fix ad hoc instance intersection logic (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/9909">9909</a>)
<li>Support tuple multiplication with literal integers (hatal175, PR <a href="https://github.com/python/mypy/pull/10361">10361</a>)
<li>Fix recursion issue with nested instances and unions (Peilonrayz, PR <a href="https://github.com/python/mypy/pull/9663">9663</a>)
<li>Fix caching behavior of PEP561-installed namespace packages (Michael J. Sullivan, PR <a href="https://github.com/python/mypy/pull/10937">10937</a>)
<li>Add <tt>__dataclass_fields__</tt> and <tt>__attrs_attrs__</tt> to dataclasses (Timofey Kukushkin, PR <a href="https://github.com/python/mypy/pull/8578">8578</a>)
<li>Fix argument checking on empty dict with double stars (Momoko Hattori, PR <a href="https://github.com/python/mypy/pull/9629">9629</a>)
<li>Fix some type-guard-related crashes (Shantanu, PR <a href="https://github.com/python/mypy/pull/11061">11061</a>)
<li>Reject <tt>raise</tt> <tt>Err</tt> if <tt>Err</tt> can’t be called without arguments (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11125">11125</a>)
<li>Fix <tt>TypedDict</tt> crash with function definition (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11126">11126</a>)
<li>Report attribute access errors for type variable bound to a union (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/11140">11140</a>)
<li>Fix crash on <tt>dataclasses.field(unpack)</tt> (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11137">11137</a>)
<li>Fix crash related to <tt>ParamSpec</tt> in mypy daemon (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/11567">11567</a>)
<li>Properly type check <tt>*CustomType</tt> and <tt>CustomType</tt> function arguments (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11151">11151</a>)
<li>Fix crash with overload and callable object decorators (Shantanu, PR <a href="https://github.com/python/mypy/pull/11630">11630</a>)
<li>Fix crash involving explicit reexport, import cycle, and a wildcard (Shantanu, PR <a href="https://github.com/python/mypy/pull/11632">11632</a>)
</ul>
<h2>Mypyc Features, Fixes, and Performace Improvements</h2>
<ul>
<li>Fix class-based named tuples (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/10746">10746</a>)
<li>Add a special case for <tt>len()</tt> of a string value (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10710">10710</a>)
<li>Reject instance attribute access through class object (Jukka Lehtosalo, PR <a href="https://github.com/python/mypy/pull/10798">10798</a>)
<li>Speed up the construction of list objects (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10807">10807</a>)
<li>Add bytes primitive type (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10881">10881</a>)
<li>Add bytearray support (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10891">10891</a>)
<li>Optimize construction via <tt>list()</tt> and <tt>dict()</tt> (Richard Si, PR <a href="https://github.com/python/mypy/pull/10918">10918</a>)
<li>Speed up bytes <tt>join()</tt> method (jhance, PR <a href="https://github.com/python/mypy/pull/10929">10929</a>)
<li>Speed up <tt>len(bytes)</tt> (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10936">10936</a>)
<li>Speed up bytes indexing and slicing (PR <a href="https://github.com/python/mypy/pull/10966">10966</a>, PR <a href="https://github.com/python/mypy/pull/10950">10950</a>) (97littleleaf11)
<li>Speed up <tt>bytes.decode()</tt> and <tt>str.encode()</tt> (PR <a href="https://github.com/python/mypy/pull/10974">10974</a>, PR <a href="https://github.com/python/mypy/pull/10951">10951</a>) (97littleleaf11)
<li>Speed up bytes equality checks (jhance, PR <a href="https://github.com/python/mypy/pull/10928">10928</a>)
</ul>
<h2>Documentation Improvements</h2>
<ul>
<li>Add docs about exhaustive literal and enum checks (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/10860">10860</a>)
<li>Add ‘or’ regular expression example to <tt>--exclude</tt> documentation (Niklas Gustafsson, PR <a href="https://github.com/python/mypy/pull/10903">10903</a>)
<li>Document per-module <tt>follow_imports</tt> more explicitly (Shantanu, PR <a href="https://github.com/python/mypy/pull/10845">10845</a>)
<li>Add docs for the <tt>TypeGuard</tt> type (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/10758">10758</a>)
<li>Update type narrowing section in common issues (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11014">11014</a>)
<li>Document how <tt>--no-implicit-reexport</tt> handles <tt>from X import Y as Z</tt> (Max Marrone, PR <a href="https://github.com/python/mypy/pull/11083">11083</a>)
<li>Document <tt>strict</tt> config file option (Anders Kaseorg, PR <a href="https://github.com/python/mypy/pull/11132">11132</a>)
<li>Add better type narrowing documentation (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11088">11088</a>)
<li>Add documentation about <tt>:=</tt> and type guards (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/11161">11161</a>)
</ul>
<h2>Typeshed Updates</h2>
<p>Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library. Please see <a href="https://github.com/python/typeshed/commits/master?after=e4c2c0f3021abac1078854da92a9ec14848b32f4+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>Abdul Rehaman
<li>Anders Kaseorg
<li>Anmol Takiar
<li>Anton Agestam
<li>Chad Dombrova
<li>Christoph Tyralla
<li>Daniel Hahler
<li>Dong-hee Na
<li>Elisha Hollander
<li>Ethan Smith
<li>ethframe
<li>geo7
<li>hatal175
<li>Hugues
<li>Ilya Konstantinov
<li>Jared Hance
<li>Kevin Wojniak
<li>KotlinIsland
<li>Louis Sautier
<li>Max Marrone
<li>Mehdi ABAAKOUK
<li>Michael J. Sullivan
<li>Michael R. Crusoe
<li>Momoko Hattori
<li>Nikita Sobolev
<li>Niklas Gustafsson
<li>Nipunn Koorapati
<li>Peilonrayz
<li>pranavrajpal
<li>Richard Si
<li>ryan-gunderson
<li>Sebastian Rittau
<li>sed-i
<li>Shantanu
<li>Taneli Hukkinen
<li>Tim Gallant
<li>Timofey Kukushkin
<li>Vanessa Ung
<li>Zac Hatfield-Dodds
</ul>
<p>We’d also like to thank our employer, Dropbox, for funding the mypy core team.</body>
</html>Ivanhttp://www.blogger.com/profile/06171376418884900509noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-8406288306260377752021-06-22T11:51:00.000-07:002021-06-22T11:51:51.277-07:00Mypy 0.910 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 0.910 to the Python Package Index (<a href="https://pypi.org/project/mypy/">PyPI</a>). Mypy is a static type checker for Python. This is a small feature release that includes a new command-line option <tt>--non-interactive</tt> for installing stub (type) packages without asking for a confirmation, fixes to regressions, and a few other improvements. 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>Installing Stub Packages Non-Interactively</h2>
<p>Mypy 0.900 added <tt>--install-types</tt> to install missing stub packages. We received feedback that this wasn’t a good fit for all use cases, since it asks for interactive confirmation from the user, and it requires another mypy invocation to actually perform type checking.
<p>This release adds the new option <tt>--non-interactive</tt> that can be used with <tt>--install-types</tt> to install suggested stub packages without asking for confirmation. This can be useful in Continuous Integration jobs. The option causes mypy to both install stub packages and perform type checking within a single invocation. When not using <tt>--non-interactive</tt>, you’d have to run mypy again to get up-to-date results with the installed stubs.
<p>Here’s an example of using <tt>--non-interactive</tt>:
<pre>
$ mypy --install-types --non-interactive src/
Installing missing stub packages:
/Users/jukka/venv/mypy/bin/python3 -m pip install types-requests
Collecting types-requests
Downloading types_requests-2.25.0-py3-none-any.whl (22 kB)
Installing collected packages: types-requests
Successfully installed types-requests-2.25.0
Success: no issues found in 15 source files
</pre>
<p>This option provides a new way to migrate existing mypy runner scripts after updating to mypy 0.9xx: just add the <tt>--install-types</tt> <tt>--</tt><tt>non-interactive</tt> options to your mypy command line.
<p>Note that <tt>--install-types</tt> currently always installs the latest stubs for all supported packages. If you want reproducible results from your builds, we recommend explicitly pinning stub package versions in your <tt>requirements.txt</tt> file, for example.
<h2>Python 3.5 Deprecation</h2>
<p>Running mypy on Python 3.5 is now deprecated. A future mypy release will drop Python 3.5 support. We haven’t decided when this will happen, but this might happen in the next feature release after 0.910.
<h2>Stubgen Improvements</h2>
<ul>
<li>Don't annotate unknown argument and return types (Sebastian Rittau, PR <a href="https://github.com/python/mypy/pull/10626">10626</a>)
<li>Never generate a variable initializer (Sebastian Rittau, PR <a href="https://github.com/python/mypy/pull/10623">10623</a>)
<li>Use <tt>NamedTuple</tt> class syntax (Sebastian Rittau, PR <a href="https://github.com/python/mypy/pull/10625">10625</a>)
<li>Use <tt>T | None</tt> (PEP 604) instead of <tt>Optional[T]</tt> (Sebastian Rittau, PR <a href="https://github.com/python/mypy/pull/10624">10624</a>)
</ul>
<h2>Other Fixes and Improvements</h2>
<ul>
<li>Fix some crashes from faulty casts (Shantanu, PR <a href="https://github.com/python/mypy/pull/10560">10560</a>)
<li>Update docs for deferral of PEP 563 to 3.11 (Smart, PR <a href="https://github.com/python/mypy/pull/10655">10655</a>)
<li>Don't suggest to install stubs for packages with <tt>py.typed</tt> files (Sebastian Rittau, PR <a href="https://github.com/python/mypy/pull/10652">10652</a>)
<li>Correct the type package name of <tt>pyopenssl</tt> ( Sebastian Rittau, PR <a href="https://github.com/python/mypy/pull/10656">10656</a>)
<li>Improve error reporting when <tt>--install-types</tt> has no cache (PR <a href="https://github.com/python/mypy/pull/10667">10667</a>)
<li>Suggest <tt>types-setuptools</tt> for <tt>pkg_resources</tt> (Sebastian Rittau, PR <a href="https://github.com/python/mypy/pull/10681">10681</a>)
<li>Fix crash with assignment to variable guarded with TypeGuard (PR <a href="https://github.com/python/mypy/pull/10683">10683</a>)
<li>Don't ask to install a stub package if stubs are installed (PR <a href="https://github.com/python/mypy/pull/10670">10670</a>)
<li>Fix crash when inferring multiple assignment with overloaded function (PR <a href="https://github.com/python/mypy/pull/10689">10689</a>)
</ul>
<h2>Typeshed Updates</h2>
<p>There are no typeshed updates in this release.
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<ul>
<li>Sebastian Rittau
<li>Shantanu
<li>Smart
</ul>
<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-5841347846662841712021-06-08T11:24:00.001-07:002021-06-09T07:02:18.379-07:00Mypy 0.900 Released<html>
<meta charset="utf-8" />
<body>
<p>We’ve just uploaded mypy 0.900 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 many 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>.
<p><b>Update:</b> Released mypy 0.901 that fixes a crash when using <t>--install-types</t>.
<h2>Third-party Library Stubs in Stub Packages (Breaking Change)</h2>
<p>Mypy now only ships with type stubs for stdlib modules (plus <tt>typing_extensions</tt> and <tt>mypy_extensions</tt>). If you use third-party libraries that don’t include stubs or inline type annotations, you can explicitly install stub packages, usually called <tt>types-<name></tt>.
<p>For example, if you use <tt>requests</tt>, you can install stubs like this:
<pre>
python3 -m pip install types-requests
</pre>
<p>If mypy can’t find stubs, it will suggest the name of the stub package to install:
<pre>
t.py:1: error: Library stubs not installed for "requests"
(or incompatible with Python 3.8)
t.py:1: note: Hint: "python3 -m pip install types-requests"
t.py:1: note: (or run "mypy --install-types" to install all
missing stub packages)
t.py:1: note: See https://mypy.readthedocs.io/en/...
</pre>
<p>You can also now run <tt>mypy</tt> <tt>--</tt><tt>install-types</tt> to install all missing stub packages in the mypy run (or the previous run, if you don’t pass any files to check):
<pre>
$ mypy --install-types
Installing missing stub packages:
/Users/jukka/venv/mypy/bin/python3 -m pip install types-requests
Install? [yN] y
Collecting types-requests
Using cached types_requests-0.1.8-py2.py3-none-any.whl (22 kB)
Installing collected packages: types-requests
Successfully installed types-requests-0.1.8
</pre>
<p><b>Note:</b> <tt>--install-types</tt> isn’t supported by mypy daemon.
<p><b>Note:</b> For security reasons, the suggested stubs are limited to only a small subset of manually selected packages that have been verified by the typeshed team. These packages include only stub files and no executable code.
<p><b>Note:</b> Even if you are using <tt>--ignore-missing-imports</tt>, mypy will ask to install stubs for packages that had bundled stubs in previous mypy releases. This helps you avoid losing type checking precision from missing stubs when upgrading to mypy 0.900.
<p>For more information, read the <a href="http://mypy-lang.blogspot.com/2021/05/the-upcoming-switch-to-modular-typeshed.html">blog post</a> about this change and why we did this. There is more detail in the <a href="https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports">docs</a>.
<h2>Python 2 Support is Opt-in (Breaking Change)</h2>
<p>If you want to type check Python 2 code, you now have to install <tt>mypy[python2]</tt> using pip (on Python 3.8 and later):
<pre>
python3 -m pip install -U mypy[python2]
</pre>
<p>This will install the additional <tt>typed-ast</tt> pip dependency that is required for Python 2 support. Type checking Python 2 code is still fully supported by mypy.
<p>This was contributed by Shantanu (PR <a href="https://github.com/python/mypy/pull/10183">10183</a>).
<h2>TypeGuard</h2>
<p>Mypy now supports defining user-defined functions that perform type narrowing, similar to <tt>isinstance</tt>. Read <a href="https://www.python.org/dev/peps/pep-0647/">PEP 647</a> for the details. Here’s an example adapted from the PEP:
<pre>
from typing_extensions import TypeGuard
def is_str_list(val: List[object]) -> TypeGuard[List[str]]:
"""Are all list items strings?"""
return all(isinstance(x, str) for x in val)
def func(val: List[object]) -> None:
if is_str_list(val):
print(" ".join(val)) # OK
</pre>
<p>Since <tt>TypeGuard</tt> will be included in Python 3.10, which hasn’t been released yet, you will have to import it from a recent version of <tt>typing_extensions</tt> for now.
<p>This was contributed by Guido van Rossum (PR <a href="https://github.com/python/mypy/pull/9865">9865</a>).
<h2>Support for pyproject.toml</h2>
<p>You can now use a <tt>pyproject.toml</tt> file instead of <tt>mypy.ini</tt> for mypy configuration. Here is an example from the <a href="https://mypy.readthedocs.io/en/latest/config_file.html#using-a-pyproject-toml-file">documentation</a>:
<pre>
# mypy global options:
[tool.mypy]
python_version = "2.7"
warn_return_any = true
warn_unused_configs = true
# mypy per-module options:
[[tool.mypy.overrides]]
module = "mycode.foo.*"
disallow_untyped_defs = true
[[tool.mypy.overrides]]
module = "mycode.bar"
warn_return_any = false
[[tool.mypy.overrides]]
module = [
"somelibrary",
"some_other_library"
]
ignore_missing_imports = true
</pre>
<p>This was contributed by Adam Weeden (PR <a href="https://github.com/python/mypy/pull/10219">10219</a>).
<h2>Binary Wheels for Apple Silicon</h2>
<p>We now include binary wheels for Apple Silicon. This can make mypy runs over 4x faster on supported hardware.
This requires a native Apple Silicon build of Python 3.9 to work.
<p>This was contributed by Jingchen Ye (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10145">10145</a>).
<h2>Type Narrowing with type(x)</h2>
<p>Mypy now recognizes that checks such as <tt>type(x) is str</tt> narrow the type of <tt>x</tt> to <tt>str</tt>. Previously you had to use <tt>isinstance(x, str)</tt>. Example:
<pre>
def example(x: Union[int, str]) -> bool:
if type(x) is str:
# Type of "v" is "str" here
...
else:
# Type of "v" is Union[int, str] here
# "v" could be a instance of a "str" subclass!
...
</pre>
<p>This was contributed by Pranav Rajpal (PR <a href="https://github.com/python/mypy/pull/10284">10284</a>).
<h2>Hosted Documentation for Mypyc</h2>
<p>We now have
hosted <a href="https://mypyc.readthedocs.io/en/latest/">user
documentation</a> for mypyc, the compiler we use to speed up
mypy. Mypyc is still experimental, but we are looking for early
adopters.
<h2>New Mypyc Features</h2>
<ul>
<li>Support <tt>__setitem__</tt>, <tt>__delitem__</tt>, <tt>__len__</tt> and <tt>__contains__</tt> in native classes (PR <a href="https://github.com/python/mypy/pull/10451">10451</a>)
<li>Basic support for class-based named tuples (PR <a href="https://github.com/python/mypy/pull/10252">10252</a>)
<li>Support class-based TypedDict definitions (PR <a href="https://github.com/python/mypy/pull/10226">10226</a>)
</ul>
<h2>Mypyc Performance Improvements</h2>
<ul>
<li>Pre-allocate space in list comprehensions (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10295">10295</a>)
<li>Faster <tt>dict</tt> true test (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10333">10333</a>)
<li>Implement <tt>dict.setdefault</tt> primitive (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10286">10286</a>)
<li>Optimize truth value testing for strings (pranavrajpal, PR <a href="https://github.com/python/mypy/pull/10269">10269</a>)
<li>Faster set creation with generator expression (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10261">10261</a>)
<li>Add a primitive for loading the <tt>bool</tt> type (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10257">10257</a>)
<li>Faster creation of a tuple from list/tuple (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10217">10217</a>)
<li>Use vectorcalls to speed up calls to Python objects (PR <a href="https://github.com/python/mypy/pull/10153">10153</a>)
<li>Add primitive for <tt>str.replace</tt> (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10088">10088</a>)
<li>Add primitives for <tt>list.index()</tt> and <tt>list.remove()</tt> (PR <a href="https://github.com/python/mypy/pull/9961">9961</a>)
<li>Intern string literals (PR <a href="https://github.com/python/mypy/pull/9960">9960</a>)
<li>Add fast path for simple calls in wrapper functions (PR <a href="https://github.com/python/mypy/pull/9948">9948</a>)
<li>Use METH_FASTCALL with <tt>__call__</tt> (PR <a href="https://github.com/python/mypy/pull/9946">9946</a>)
<li>Use faster METH_FASTCALL wrapper functions on Python 3.7+ (PR <a href="https://github.com/python/mypy/pull/9894">9894</a>)
<li>Add primitives for <tt>list.sort()</tt> and <tt>list.reverse()</tt> (PR <a href="https://github.com/python/mypy/pull/9897">9897</a>)
<li>Recognize <tt>six.moves.xrange</tt> as an alias of <tt>range</tt> (PR <a href="https://github.com/python/mypy/pull/9896">9896</a>)
<li>Some tagged integer micro-optimizations (PR <a href="https://github.com/python/mypy/pull/9801">9801</a>)
<li>Add primitive for <tt>dict.copy</tt> (vsakkas, PR <a href="https://github.com/python/mypy/pull/9721">9721</a>)
</ul>
<h2>Other Mypyc Fixes and Improvements</h2>
<ul>
<li>Fix reference counting in <tt>dict.setdefault</tt> (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10334">10334</a>)
<li>Don't coerce types checked with <tt>isinstance</tt> (Sara Sinback, PR <a href="https://github.com/python/mypy/pull/10245">10245</a>)
<li>Simplify argument parsing in legacy wrapper functions (PR <a href="https://github.com/python/mypy/pull/10234">10234</a>)
<li>Simplify generated C by omitting gotos to the next block (PR <a href="https://github.com/python/mypy/pull/10230">10230</a>)
<li>Box initializers of final variables when required (PR <a href="https://github.com/python/mypy/pull/10229">10229</a>)
<li>Fix compilation of unreachable expressions (PR <a href="https://github.com/python/mypy/pull/10228">10228</a>)
<li>Foundational support for tuple literals (and <tt>None</tt> and <tt>bool</tt> literals, PR <a href="https://github.com/python/mypy/pull/10148">10148</a>)
<li>Use tables to construct and store literals (PR <a href="https://github.com/python/mypy/pull/10147">10147</a>)
<li>Fix overflow error handling in <tt>list.insert</tt> (PR <a href="https://github.com/python/mypy/pull/9895">9895</a>)
<li>Always add implicit <tt>None</tt> return type to <tt>__init__</tt> method (Thomas Johnson, PR <a href="https://github.com/python/mypy/pull/9866">9866</a>)
<li>Small documentation updates (Thomas Johnson, PR <a href="https://github.com/python/mypy/pull/10184">10184</a>)
<li>Updates to introduction in the documentation (PR <a href="https://github.com/python/mypy/pull/10179">10179</a>)
<li>Various small doc updates (PR <a href="https://github.com/python/mypy/pull/10177">10177</a>)
<li>Make mypyc docs use the same theme as mypy docs (PR <a href="https://github.com/python/mypy/pull/10176">10176</a>)
<li>Fix mypyc failing to compile on CPython 3.10.0a6 (Adrian Freund, PR <a href="https://github.com/python/mypy/pull/10202">10202</a>)
<li>Avoid declaring variable in C for loop initialization (Thomas Johnson, PR <a href="https://github.com/python/mypy/pull/10091">10091</a>)
</ul>
<h2>Stubgen Improvements</h2>
<ul>
<li>Properly convert overloaded functions (Chad Dombrova, PR <a href="https://github.com/python/mypy/pull/9613">9613</a>)
<li>Fix invoking <tt>mro()</tt> (Gen Xu, PR <a href="https://github.com/python/mypy/pull/10138">10138</a>)
<li>Render a bit better stubs (Sergei Izmailov, PR <a href="https://github.com/python/mypy/pull/9903">9903</a>)
<li>Fixed <tt>Any</tt> and <tt>Dict</tt> missing from stubgen imports list (Ashley Whetter, PR <a href="https://github.com/python/mypy/pull/9900">9900</a>)
<li>Fix type error (Shantanu, PR <a href="https://github.com/python/mypy/pull/10523">10523</a>)
<li>Fixes and typos (Sergei Izmailov, PR <a href="https://github.com/python/mypy/pull/9877">9877</a>)
</ul>
<h2>Stubtest Improvements</h2>
<ul>
<li>Improve build error messages (Shantanu, PR <a href="https://github.com/python/mypy/pull/10365">10365</a>)
<li>Check overloads are functions, don't early return (Shantanu, PR <a href="https://github.com/python/mypy/pull/10258">10258</a>)
<li>Fix signature construction for overload + implicit classmethod (Shantanu, PR <a href="https://github.com/python/mypy/pull/9921">9921</a>)
</ul>
<h2>Documentation Updates</h2>
<ul>
<li>Add security documentation for <tt>--install-types</tt> (Adam Weeden, PR <a href="https://github.com/python/mypy/pull/10555">10555</a>)
<li>Improve documentation of extending mypy (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/10222">10222</a>)
<li>Update documentation links (Shantanu, PR <a href="https://github.com/python/mypy/pull/10159">10159</a>)
<li>Fix incomplete error codes documentation (Iulian Onofrei, PR <a href="https://github.com/python/mypy/pull/9799">9799</a>)
<li>Document <tt>explicit_package_bases</tt> config file option (Sam Bull, PR <a href="https://github.com/python/mypy/pull/10020">10020</a>)
<li>Clarify that <tt>mypy_path</tt> is relative to current working directory (Gustav Gränsbo, PR <a href="https://github.com/python/mypy/pull/9959">9959</a>)
<li>Emphasise that users probably want <tt>--follow-imports=normal</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/9955">9955</a>)
</ul>
<h2>Other Notable Fixes and Improvements</h2>
<ul>
<li>Make <tt>ignore_missing_imports</tt> work for third-party libraries which previously had bundled stubs (PR <a href="https://github.com/python/mypy/pull/10582">10582</a>)
<li>Restrict the number of errors shown when there are missing stubs (PR <a href="https://github.com/python/mypy/pull/10579">10579</a>)
<li>Mention <tt>fullname</tt> of <tt>PlaceholderNode</tt> in assertion to simplify debugging (Adam Weeden, PR <a href="https://github.com/python/mypy/pull/10565">10565</a>)
<li>Use double quotes in error messages instead of single quotes (Dixith)
<li>Use double quotes in various error messages (Prasanth Chettri, PR <a href="https://github.com/python/mypy/pull/10053">10053</a>)
<li>Fix crash on TypeGuard plus "and" (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/10496">10496</a>)
<li>Fix spurious name undefined error in class body within import cycle (PR <a href="https://github.com/python/mypy/pull/10498">10498</a>)
<li>Remove assertion from TypeGuard serialization (Jelle Zijlstra, PR <a href="https://github.com/python/mypy/pull/10486">10486</a>)
<li>Do not allow to use <tt>Final</tt> and <tt>ClassVar</tt> at same time (Yurii Karabas, PR <a href="https://github.com/python/mypy/pull/10478">10478</a>)
<li>Allow running mypy if Python 2 typeshed stubs aren't installed (PR <a href="https://github.com/python/mypy/pull/10494">10494</a>)
<li>Allow inline comments in VERSIONS (Sebastian Rittau, PR <a href="https://github.com/python/mypy/pull/10472">10472</a>)
<li>Infer unreachability for <tt>await no_return()</tt> (Shantanu, PR <a href="https://github.com/python/mypy/pull/10458">10458</a>)
<li>Fix unresolved reference + tuples crashing (EXPLOSION, PR <a href="https://github.com/python/mypy/pull/10401">10401</a>)
<li>Fix crash with type alias inside <tt>__init__</tt> in incremental mode (PR <a href="https://github.com/python/mypy/pull/10432">10432</a>)
<li>Fix crash with nested NamedTuple in incremental mode (PR <a href="https://github.com/python/mypy/pull/10431">10431</a>)
<li>Fix crash related to module-level <tt>__getattr__</tt> in incremental mode (PR <a href="https://github.com/python/mypy/pull/10430">10430</a>)
<li>Add support for <tt>functools.cached_property</tt> (Marc Mueller, PR <a href="https://github.com/python/mypy/pull/10408">10408</a>)
<li>Don't narrow <tt>Type[X]</tt> with a metaclass (PR <a href="https://github.com/python/mypy/pull/10424">10424</a>)
<li>Remove note: setup.cfg <i>does</i> need <tt>[mypy]</tt> section (James Cooke, PR <a href="https://github.com/python/mypy/pull/10364">10364</a>)
<li>Fix inference of <tt>IntEnum</tt> value attribute type (Python 2, PR <a href="https://github.com/python/mypy/pull/10417">10417</a>)
<li>Don't report error when using <tt>total_ordering</tt> in Python 2 mode (PR <a href="https://github.com/python/mypy/pull/10416">10416</a>)
<li>Fix narrowing down TypedDict unions with enum literal types (PR <a href="https://github.com/python/mypy/pull/10415">10415</a>)
<li>Fix inference of <tt>IntEnum</tt> value attribute type (PR <a href="https://github.com/python/mypy/pull/10412">10412</a>)
<li>Use <tt>typeddict-item</tt> error code for more errors (PR <a href="https://github.com/python/mypy/pull/10410">10410</a>)
<li>Fix a bunch of tests broken by python 3.10 (Adrian Freund, PR <a href="https://github.com/python/mypy/pull/10404">10404</a>)
<li>Support maximum version marker of stdlib typeshed modules (Sebastian Rittau, PR <a href="https://github.com/python/mypy/pull/10402">10402</a>)
<li>First look into <tt>@python2</tt> subdirectory of search path items in Python 2 mode (PR <a href="https://github.com/python/mypy/pull/10392">10392</a>)
<li>Make enum type compatible with union of all enum item literals (PR <a href="https://github.com/python/mypy/pull/10388">10388</a>)
<li>Fix an issue with union types containing literals (Adrian Freund, PR <a href="https://github.com/python/mypy/pull/10373">10373</a>)
<li>Fix re-exporting <tt>__all__</tt> in a stub file (PR <a href="https://github.com/python/mypy/pull/10382">10382</a>)
<li>Extend the dataclass plugin to deal with callable properties (Aaron Ecay, PR <a href="https://github.com/python/mypy/pull/10292">10292</a>)
<li>Make TypedDict incompatible type message more understandable (Akshay K, PR <a href="https://github.com/python/mypy/pull/10326">10326</a>)
<li>Make <tt>--explicit-package-bases</tt> invertible (Gustav Gränsbo, PR <a href="https://github.com/python/mypy/pull/9969">9969</a>)
<li>Fix crash for protocol classes and <tt>Hashable</tt> false negative (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/10308">10308</a>)
<li>Fix strict equality false positive when strict optional disabled (Kamil Turek, PR <a href="https://github.com/python/mypy/pull/10174">10174</a>)
<li>Issue an error when overriding typeguard with non-typeguard in subclass (Kamil Turek, PR <a href="https://github.com/python/mypy/pull/10300">10300</a>)
<li>Support <tt>functools.total_ordering</tt> (Ashley Whetter, PR <a href="https://github.com/python/mypy/pull/7831">7831</a>)
<li>Support reversed operand order when comparing against <tt>sys.version_info</tt> (Kamil Turek, PR <a href="https://github.com/python/mypy/pull/10288">10288</a>)
<li>Only import <tt>distutils</tt> if it is needed (Adrian Freund, PR <a href="https://github.com/python/mypy/pull/10203">10203</a>)
<li>Recombine complete union of enum literals into original type (PR <a href="https://github.com/python/mypy/pull/9097">9097</a>, PR <a href="https://github.com/python/mypy/pull/9063">9063</a>) (Ethan Leba)
<li>Support union type arguments when showing protocol member conflicts (97littleleaf11, PR <a href="https://github.com/python/mypy/pull/10154">10154</a>)
<li>Fix recently added enum value type prediction (Paddy, PR <a href="https://github.com/python/mypy/pull/10057">10057</a>)
<li>Support subclassing of <tt>NodeVisitor</tt> and <tt>TraverserVisitor</tt> in plugins (Nikita Sobolev, PR <a href="https://github.com/python/mypy/pull/10125">10125</a>)
<li>Speed up processing of new files in daemon by caching ASTs (PR <a href="https://github.com/python/mypy/pull/10128">10128</a>)
<li>Add narrowing and closures to common issues (Shantanu, PR <a href="https://github.com/python/mypy/pull/9956">9956</a>)
<li>Add Python script to build wheels using cibuildwheel (PR <a href="https://github.com/python/mypy/pull/10096">10096</a>)
<li>Don't try to follow imports to <tt>encodings.*</tt> (PR <a href="https://github.com/python/mypy/pull/10094">10094</a>)
<li>Speed up case sensitive is-file check in file system cache (PR <a href="https://github.com/python/mypy/pull/10093">10093</a>)
<li>Use fast path for finding modules in mypy daemon (PR <a href="https://github.com/python/mypy/pull/10095">10095</a>)
<li>Fix following stub imports in daemon when using <tt>--follow-imports=skip</tt> (PR <a href="https://github.com/python/mypy/pull/10092">10092</a>)
<li>Use <tt>sys.executable</tt> instead of <tt>python3</tt> for <tt>--install-types</tt> (Anthony Sottile, PR <a href="https://github.com/python/mypy/pull/10086">10086</a>)
<li>Add <tt>build-requirements.txt</tt> to MANIFEST.in (PR <a href="https://github.com/python/mypy/pull/10071">10071</a>)
<li>Add separate requirements file for mypy self-compile (PR <a href="https://github.com/python/mypy/pull/10069">10069</a>)
<li>Expand user home for <tt>cache_dir</tt> (Marco Zatta, PR <a href="https://github.com/python/mypy/pull/10051">10051</a>)
<li>Fix daemon crash when deleting packages (PR <a href="https://github.com/python/mypy/pull/10036">10036</a>)
<li>Keep track of fine-grained dependencies for modules in typeshed (PR <a href="https://github.com/python/mypy/pull/10034">10034</a>)
<li>Fix import following issue in daemon (PR <a href="https://github.com/python/mypy/pull/10032">10032</a>)
<li>Fix mypy daemon crash when following from a new module (PR <a href="https://github.com/python/mypy/pull/10030">10030</a>)
<li>Detect invalid value for <tt>--custom-typeshed-dir</tt> (PR <a href="https://github.com/python/mypy/pull/9985">9985</a>)
<li>Fix <tt>pip install</tt> for new typeshed (Ivan Levkivskyi, PR <a href="https://github.com/python/mypy/pull/9976">9976</a>)
<li>Report incompatible assignments for descriptors with overloaded <tt>__set__</tt> methods (Christoph Tyralla, PR <a href="https://github.com/python/mypy/pull/9893">9893</a>)
<li>Fix <tt>TypedDict.get("missing_key")</tt> with string literal (Adrian Freund, PR <a href="https://github.com/python/mypy/pull/9906">9906</a>)
</ul>
<h2>Acknowledgements</h2>
<p>Thanks to all mypy contributors who contributed to this release:
<ul>
<li>Aaron Ecay
<li>Adam Weeden
<li>Adrian Freund
<li>Akshay K
<li>Akuli
<li>Anthony Sottile
<li>Arjun
<li>Ashley Whetter
<li>Chad Dombrova
<li>Christoph Tyralla
<li>Dixith
<li>Ethan Leba
<li>EXPLOSION
<li>Gen Xu
<li>Gustav Gränsbo
<li>hatal175
<li>Iulian Onofrei
<li>James Cooke
<li>Jelle Zijlstra
<li>Jesús Cea
<li>Jingchen Ye (97littleleaf11)
<li>Kamil Turek
<li>Kyle Verhoog
<li>Marc Mueller
<li>Marco Gorelli
<li>Marco Zatta
<li>Nikita Sobolev
<li>Paddy
<li>Philip Jägenstedt
<li>Pranav Rajpal
<li>Prasanth Chettri
<li>Raphael Gaschignard
<li>Reda Bouaida
<li>Saiprasad Kale
<li>Sam Bull
<li>Sara Sinback
<li>Sebastian Rittau
<li>Sergei Izmailov
<li>Shantanu
<li>Thomas Johnson
<li>vsakkas
<li>wwuck
<li>Xuanda Yang
<li>Yurii Karabas
</ul>
<p>Additional thanks to all contributors to <a href="https://github.com/python/typeshed">typeshed</a>:
<ul>
<li>Adrian Freund
<li>Akuli
<li>Alexander Reynolds
<li>Andre Delfino
<li>Andrew Crabtree
<li>Andrew Zhou
<li>Andrey
<li>Ankur Singh
<li>Anthony Sottile
<li>Anton Agestam
<li>Arie Bovenberg
<li>Árni Már Jónsson
<li>Ashwin Ramaswami
<li>baterflyrity
<li>Cássio Botaro
<li>Christopher Dignam
<li>Christopher Gurnee
<li>Christopher Sang
<li>Daniel Rosenwasser
<li>danieleades
<li>Dante Camarena
<li>David Barker
<li>Dean Way
<li>dearoneesama
<li>dod-wdwilcox
<li>Dominic Davis-Foster
<li>Edgar Handal
<li>Eric Traut
<li>Erik Soma
<li>Giel van Schijndel
<li>Gilad Reti
<li>Greg Ward
<li>Guilhem C
<li>Guillaume Ayoub
<li>harens
<li>hatal175
<li>Henry Schreiner
<li>heroesm
<li>Igor Nehoroshev
<li>Ilya Konstantinov
<li>Iwan
<li>jack1142
<li>Jacob Hayes
<li>Jake Bailey
<li>James
<li>James Morris
<li>Jason Huang
<li>Jelle Zijlstra
<li>Jia Chen
<li>John T. Wodder II
<li>Jon Banafato
<li>Jon Dufresne
<li>JonathanMeans
<li>Jörg Herbel
<li>Jürgen Gmach
<li>Kaleb Barrett
<li>Ken Odegard
<li>krouziciorel
<li>Kyle Altendorf
<li>ldruschk
<li>Mahmoud Harmouch
<li>Marat Sharafutdinov
<li>Mark Vismonte
<li>Marks Polakovs
<li>Marti Raudsepp
<li>Mathieu Parent
<li>Maxime Arthaud
<li>Mohit Goyani
<li>MrGreenTea
<li>n0ob404
<li>naglis
<li>Nick Crews
<li>Nick M
<li>Nipunn Koorapati
<li>Philipp Hahn
<li>Rebecca Chen
<li>Ricardo
<li>rijenkii
<li>Rune Tynan
<li>Ryan McCampbell
<li>sachindavra
<li>Sam Bull
<li>Sean B. Palmer
<li>Sebastian Rittau
<li>Shantanu
<li>Sorin Sbarnea
<li>spaghEddieDoyle
<li>Stanislav Levin
<li>Steve B
<li>Tadek Kijkowski
<li>Takumi Kato
<li>Terence Honles
<li>Thomas Cellerier
<li>Tigran Kostandyan
<li>Tushar Sadhwani
<li>Udi Fuchs
<li>Utsav
<li>Vasily Zakharov
<li>Viktor Roytman
<li>Vyom Pathak
<li>Wilfredo Sánchez Vega
<li>Wolf Honore
<li>Yehuda Davis
</ul></body>
</html>
Jukka Lehtosalohttp://www.blogger.com/profile/00122775610277203624noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-85802082039359393992021-05-26T03:41:00.000-07:002021-05-26T03:41:21.394-07:00The Upcoming Switch to Modular Typeshed<html>
<meta charset="utf-8" />
<body>
<p>Mypy has been bundling stubs for many third-party libraries from <a href="https://github.com/python/typeshed">typeshed</a>, a repository of type definitions for Python packages. Mypy uses the stubs to type check code that uses these libraries, and they allow more types to be inferred by mypy. Typeshed is not just for mypy — it’s also used by several other tools in the Python typing ecosystem.
<p>Mypy will no longer include stubs for third-party libraries in the soon-to-be-released mypy 0.900 release. Instead, mypy will only ship stubs for standard library modules, while stubs for third-party libraries can be independently installed using pip. For example, if you use requests, you can install the stubs like this:
<pre>
python3 -m pip install types-requests
</pre>
<p>The stub packages are named <tt>types-<project name></tt>. Note that the project name may be different from the runtime package name. For example, stubs for the <tt>yaml</tt> package are available in <tt><a href="https://pypi.org/project/types-PyYAML/">types-PyYAML</a></tt>.
<h2>Steps for Mypy Users</h2>
<p>When you update to mypy 0.900 (once it has been released), you’ll likely get errors about missing stubs. Mypy will suggest the stub package that should be installed. Here’s an example output from mypy:
<pre>
a.py:1: error: Library stubs not installed for "requests"
a.py:1: note: Hint: "python3 -m pip install types-requests"
a.py:1: note: (or run "mypy --install-types" to install all
missing stub packages)
a.py:1: note: See https://mypy.readthedocs.io/en/...
</pre>
<p>You can now run <tt>mypy --install-types</tt> to install all the missing dependencies (unless you are using mypy daemon). Alternatively, you can install the stubs manually using pip as suggested by mypy.
<p>As a final step, you may want to add the stub packages to the build or test dependencies of your project, often in <tt>requirements.txt</tt>. You can use <tt>pip freeze</tt> to help pin to the current installed versions of the stubs. For example, you might add this line to your <tt>requirements.txt</tt>:
<pre>
types-requests==0.1.8
</pre>
<p>Currently stub packages are mostly versioned independently of the implementation package. However, it’s possible to update stub metadata in typeshed to have the versioning better reflect the target implementation package version.
<h2>Motivation</h2>
<p>The bundling of stubs with mypy has been convenient, but it also has caused a lot of friction, especially for users with many third-party dependencies. Here are the main benefits of unbundling stubs:
<ul>
<li><b>Updating stubs without updating mypy.</b> Right now it’s not straightforward to update bundled stubs to a newer version without also updating mypy. Soon you can use pip to update to the latest stubs, without having to update to mypy as well.
<li><b>Updating mypy without updating stubs.</b> Updating stubs or installing new stubs sometimes results in additional mypy errors, due to newly added but too restrictive types in stubs, or newly introduced but correct types that expose incorrect types in your code. Previously mypy users had to deal with these errors when updating mypy, which complicated the update process. Soon you’ll be able to update mypy without updating third-party stubs. Standard library stubs will still be bundled for convenience, since all mypy users need them, and they tend to be easier to validate for correctness.
<li><b>Faster access to new stubs and improvements.</b> If new stubs or stub improvements are contributed to typeshed, previously you had to wait for a new mypy release that includes them, or deal with a custom, unsupported typeshed set-up that hasn’t been properly tested. With mypy 0.900, you will be able to install or update stub packages whenever you want. As soon as a change to a stub is merged, typeshed will automatically upload a fresh stub package to PyPI. If you are not happy with some stub changes or encounter an issue, you can easily contribute fixes and start using the updated stubs, or continue to use older stubs if you so wish.
<li><b>Lower barrier to contributing new stubs.</b> Since previously every user would get all contributed stubs, each new stub was a somewhat risky proposition. If some types were incorrect, or if there were missing definitions in the stubs, this could result in many false positives. Modular typeshed lets each user individually decide whether to start using the contributed stubs, making the impact of glitches in stubs lower. The faster iteration speed should also make it more likely that issues will be fixed soon.
<li><b>Consistency.</b> Previously some third-party library stubs were bundled with mypy, some were bundled with the main implementation (upstream) package, and some were available on PyPI as separate stub packages. Now there will be one fewer option: you’d either use stubs or types included with the implementation package, or install a stub package. Types included with the main package are the preferred option, but many packages still don’t have them. Stub packages will be common for some time. Installing, versioning and updating stubs and implementation packages will also be more similar.
<li><b>Support for multiple library versions.</b> Libraries may introduce backward incompatible API changes, such as removing deprecated features. Sometimes, for various reasons, you may want to continue using an older version of a library. Now it will be easy to also continue using an older version of stubs, since library stubs are independently versioned. This also opens the option of maintaining separate stubs for versions 1.x and 2.x of a library, for example.
</ul>
<h2>Vendoring Stubs</h2>
<p>If you don’t want to deal with installing stub packages, mypy 0.900 will support vendoring stubs (i.e., maintaining a local copy in your repository). First, you can copy some stubs from typeshed into a directory, and point the <tt>MYPYPATH</tt> environment variable (or <tt>mypy_path</tt> in the mypy configuration file) to it. Mypy will look for stubs in that directory. For example, you could use a directory named <tt>stubs</tt> in your repository structured like this:
<ul>
<li><tt>stubs/toml.pyi</tt>
<li><tt>stubs/yaml/__init__.pyi</tt>
<li>…
</ul>
<p>If your project supports both Python 2 and 3, you can have stubs for Python 2 in a <tt>@python2</tt> subdirectory of the main stub directory:
<ul>
<li><tt>stubs/foobar.pyi</tt> (used for Python 3)
<li><tt>stubs/@python2/foobar.pyi</tt> (used for Python 2)
</ul>
<p>If you include <tt>stubs</tt> in the mypy search path, <tt>stubs/@python2</tt> will automatically be used for Python 2 stubs.
<h2>Feedback?</h2>
<p>Feel free to open a <a href="https://github.com/python/mypy/issues">GitHub issue</a> if you have concerns about this new approach of distributing stubs.
<h2>Acknowledgements</h2>
<p>Ivan Levkivskyi set up the infrastructure for automatically uploading stub packages to PyPI and implemented the necessary changes to typeshed.
</body>
</html>
Jukka Lehtosalohttp://www.blogger.com/profile/00122775610277203624noreply@blogger.comtag:blogger.com,1999:blog-395821797583837933.post-42110872224673962962021-03-17T06:26:00.000-07:002021-03-17T06:26:17.676-07:00Summer of Code with Mypy<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div class="wrapper">
<section>
<p>
<strong>TH3CHARLie, Xuanda Yang</strong>
<br>
th3charlie at gmail dot com
<br>
<a href="https://github.com/TH3CHARLie">GitHub Profile</a>
<br>
<a href="https://summerofcode.withgoogle.com/archive/2020/projects/6358477695352832/">GSoC Project Page</a>
<br>
<a href="https://th3charlie.github.io/gsoc2020/">GSoC Submission Page</a>
</p>
<h2 id="Introduction">Introduction</h2>
<p>
In Fall 2019, I was writing a course project in Python and was tired of the experience of finding type errors at the last minute, so I did some searching and tried mypy for the first time. At that time, I would not dream of doing a three-month coding project with the organization, which became reality last summer. In this post, I'd like to share the story of this very personal experience and talk about how I started to contribute to mypy and eventually became a Google Summer of Code (GSoC) student of this project.
</p>
<h2 id="PreApplication">Pre-application</h2>
<p>
After finishing my course project with mypy, out of curiosity, I took a look at its GitHub page and paid extra attention to the issue tracker. I searched for issues with the "good first issue" label and was surprised to find that most of them were equipped with comments from the maintainers telling how to tackle them. Reading through these comments, I found some issues that fit my level and started to take a try at them.
</p>
<p>
Before submitting a pull request, I read through the repository and checked every material that seemed useful for writing a PR, which includes the README file, the documentation and the wiki page. I learned about how to install the development version of mypy, how to test my PR locally and some high-level ideas about the codebase. This proves to save a lot of trouble in my future contributions to the project. My first PR to the project was <a href="https://github.com/python/mypy/pull/7878"> Support Negative Int Literal</a> and was reviewed by Ivan. He patiently guided me to refine the PR step by step and finally merged it into the main branch. The satisfaction of seeing my code entering the codebase of a tool used by people around the globe was huge and encouraged me to take more attempts on other good first issues. By the end of 2019, I had submitted around 20 PRs to the repository. Most of them were super simple tasks, like producing meaningful error messages or fixing a corner case of a specific type-checking rule.
</p>
<p>
Looking back now, writing all these simple PRs helped me gradually familiarize myself with the codebase and the development workflow, which became a valuable asset when applying to the GSoC project.
</p>
<h2 id="Apply">Applying to GSoC</h2>
<p>
Google Summer of Code (GSoC) is an annual event where students get to work with open source communities through the summer and even get some stipends from Google. Before Google announced last year's selected organizations and project ideas on Feb 20th, one of mypy's maintainers posted an issue named <a href="https://github.com/python/mypy/issues/8373">Project ideas</a> listing several time-consuming project ideas. At that time, I was eager to try something more challenging than fixing small bugs so I spent some time reading them through and tried to figure out which of them fit my level. A few days later, the official organization list for GSoC 2020 was out and mypy was one of them and the previously mentioned issue included the potential project ideas. What a great match, I said to myself. So I made my mind and started to draft my application.
</p>
<p>
The student application of GSoC usually consists of two parts. The first is (are) mandatory project proposal(s). Each student can choose up to three project ideas from three different organizations. Finding suitable project ideas from hundreds of them is usually hard since understanding the idea descriptions already requires effort and even some domain knowledge. Thanks to my previous contribution experience at mypy, I didn't spend too much time on this matter and quickly narrowed my topic to compiler related ones. <a href="https://github.com/mypyc/mypyc/issues/709">Generalize mypyc IR to Make non-C Backends Possible</a> from mypy and another topic from LLVM were my choices. However, the latter one was picked by someone else through the mailing list before I even had the chance to take a closer look at it. So mypy became the only organization left for me to apply to.
</p>
<p>
To write a good proposal, I started to discuss directly with the maintainers (or future mentors) in the issue tracker. I'd say this is one of the best approaches to prepare your proposal. By doing this, you are essentially expressing your passion, demonstrating your background and skills directly to the mentors and the mentors can provide details of the project that help you get a better picture. Don't be afraid to discuss, open-source communities often have very nice people and mypy is definitely one of them. Jukka Lehtosalo and Michael (Sully) Sullivan provided tons of good advice that helped me formulate a plan for the project and therefore finish my proposal. I also came up with a prototype PR addressing one core change of my proposal before the deadline. Although it never got merged since we did it differently later, a working prototype is always welcomed and I'd say it would increase your chance of getting accepted.
</p>
<p>
The second and also the optional part is the organization-specific requirement(s). Last year for applicants to mypy, there were some <a href="https://github.com/python/mypy/issues/8373#issuecomment-601127924">posted requirements</a> including course background, programming skills, submitted PRs and an email giving details.
</p>
<p>
After I submitted my proposal to GSoC's official site and sent an email to the mypy team, I did a short video interview with the mypy team. I talked about what I would do to make the project successful and also talked a little more about my background other than what was written in the email. The interview went quite well and several days later, I received an email from the mypy team and was told I was selected by the organization. Then all I had to do was to wait for the official announcement from Google. And days later, I officially became the first GSoC student of the mypy project and would start my coding summer soon.
</p>
<h2 id="Coding">Coding Through the Summer</h2>
<p>
After getting accepted to GSoC, what's left is to code through the summer. The project I worked on was Generalize mypyc IR to Make non-C Backends Possible. In short, it was a project to redesign and refactor some parts of the old mypyc IR to remove the embedded C backend-specific information. You can find the detailed technique report on the <a href="https://th3charlie.github.io/gsoc2020/">submission page</a>. Here, I'd like to talk about other things that play as important a role as coding.
</p>
<p>
Plan the schedule and monitor the progress. Three months is just a blink of an eye, so it's important to have realistic goals to achieve at specific timestamps, to make sure the project goes smoothly. We had a rough schedule in the proposal and established monthly goals in later discussions. With the schedule and goals in mind, I was able to make progress continuously. I even had an extra week. Usually, before the coding period starts in June, there is one month for community bonding where students get to familiarize themselves with the workflow of the project and connect with the mentors. Thanks to my previous mypy contribution experience, I thought it would be fine to skip this period and start coding one week earlier than scheduled. This extra week gave my mentors and me a lot of flexibility to handle unexpected schedule delays.
</p>
<p>
Communication is the key. Jukka, one of my mentors, told me that it was always hard to come up with the perfect design at first as requirements and needs develop all the time. To face this developing nature, we communicated a lot. I had daily syncs with my mentors through Gitter chat, weekly meetings with Jukka, and monthly meetings with both Jukka and Sully. In all these meetings, I shared recent progress, they helped me remove any blockers, and we discussed component designs. I am one-hundred percent sure that this project would never have been this successful without such frequent and effective communication.
</p>
<h2 id="After">After the Summer</h2>
<P>
I completed this project and submitted the required materials in early September, with around 60 PRs merged into the repository. To me, the GSoC project ended pretty well, I received the certificate from Google as well as some stipends. More importantly, I've demonstrated my passion and skills to contribute to this organization more than just a community contributor. I was honored to become one of mypy's committers. That means a lot to me and I am looking forward to contributing more to the community.
</p>
<p>
That's my story with mypy through the Google Summer of Code 2020. I hope this post will provide some useful information to future potential applicants including applicants of this year since mypy has officially been selected as one of this year’s organizations. If you have any questions regarding this post, feel free to send me an email and I will be more than happy to discuss.
</p>
<h2 id="Acknowledgements">Acknowledgements</h2>
<p>
I'd like to express my sincere gratitude to every person and organization that made my GSoC 2020 adventure possible. I'd like to firstly thank Google and mypy for providing me this opportunity.
</p>
<p>
Especially, I'd like to thank my mentors Jukka Lehtosalo and Michael Sullivan. We had daily syncs every day on Gitter and weekly/monthly video meetings via Zoom. In every discussion, they helped me clean my thoughts and find out the best approach to meet our goals. They responded quickly to my PRs, giving high-quality review comments and suggestions. They mentored me with patience and passion and I feel connected even though we are several timezones/continents away. Their guidance is even beyond the scope of the project and helps me form good software engineering skills along the way.
</p>
<p>
I also would like to thank my parents for supporting me working on this project and Yaozhu Sun from the University of Hong Kong, who lit my passion for the field of compilers and programming languages two years ago. Finally, I'd like to thank Kanemura Miku from Hinatazaka 46 for all the mental support during this special summer.
</p>
<h2 id="Disclaimer">Disclaimer</h2>
<p>
All content of this post only represents the author's personal opinions. The post does not, in any degree, constitute the view or opinion from Google or the mypy community.
</p>
</section>
</div>
<script src="javascripts/scale.fix.js"></script>
</body>
</html>
TH3CHARLiehttp://www.blogger.com/profile/04350936338693068992noreply@blogger.com