A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mypy-lang.blogspot.com/2018/07/mypy-0620-released.html below:

The Mypy Blog: Mypy 0.620 Released

We’ve just uploaded mypy 0.620 to the Python Package Index (

PyPI

). Mypy is an optional static type checker for Python. This release includes new features, bug fixes and library stub (typeshed) updates. You can install it as follows:

    python3 -m pip install -U mypy

You can read the documentation for this release on

ReadTheDocs

.

New Features Support for data classes in Python 3.7

The recently released Python 3.7 added a new module

dataclasses

that allows writing simple boilerplate-free classes. Mypy now supports this new feature:

    from dataclasses import dataclass
    from typing import List
    
    @dataclass
    class FitResult:
        optimum: List[float]
        chi: float
        method: str = "TRF"
    
    FitResult([0.1, 0.2], 1.2)  # OK
    FitResult([0.1, 0.2], 1.2, "LM")  # Also OK
    FitResult(1, 2)  # Error!
Note:

there are some limitations in supported features — see

the docs

. (Contributed by Bogdan Popa in PR

5010

.)

Overloads on generic types and other overload improvements

Mypy previously rejected certain patterns involving overloaded functions, in particular defining overloads on generic types, and calling overloads on union and optional types. These (and a few others) are now supported. In addition, the error messages for overloads are now more detailed:

    from typing import List, Union, overload
    
    @overload
    def summarize(data: List[int]) -> float: ...
    @overload
    def summarize(data: List[str]) -> str: ...
    def summarize(data):
        # Implementation goes here
        ...
    
    gen_data: Union[List[int], List[str]]
    res = summarize(gen_data)  # OK, inferred type is Union[float, str]
    
    bad_data: int
    summarize(bad_data)
    # error: No overload variant of "summarize" matches argument type "int"
    # note: Possible overload variants:
    # note:     def summarize(data: List[int]) -> float
    # note:     def summarize(data: List[str]) -> str

See

the updated docs

for more details. (Contributed by Michael Lee.)

Incomplete and partial packages

Writing complete stubs for an existing large library may be hard and sometimes impractical. To allow gradual improvements in library stubs without generating spurious errors, two mechanisms are now supported. Adding a

__getattr__

function to

__init__.pyi

indicates that the corresponding package (or subpackage) is incomplete, thus silencing

Missing library stub

errors for this package:

    # pack/__init__.pyi
    from typing import Any
    def __getattr__(arrr: str) -> Any: ...
    
    # pack/subpack/__init__.pyi
    # empty
    
    # pack/subpack/mod.pyi
    class Test: ...
    
    # main.py
    from pack import other  # OK, pack is incomplete
    other.func(1, 2)  # OK, all types in incomplete packages are Any
    
    from pack.subpack import mod  # OK
    from pack.subpack import another  # Error: missing library stub file

In addition, a PEP 561 stub package can declare itself as partial, allowing fallbacks to other sources of typing information such as inline annotations and typeshed stubs. See

PEP 561

for the details. (Contributed by Ethan Smith.)

Other Improvements and Notable Bugs Fixed Internal Improvements Acknowledgments

First of all, we’d like to thank our employer, Dropbox, for funding the mypy core team. Thanks to all mypy contributors who contributed to this release:

Additional thanks to all contributors to

typeshed

:

— Ivan Levkivskyi, on behalf of the mypy team


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4