dry-python/returns

A function wrapped with safe gets mypy error

JohnGurin opened this issue · 1 comments

Bug report

What's wrong

from dataclasses import dataclass
from dacite import from_dict
from returns.result import safe

@dataclass(frozen=True)
class Person:
    name: str
    age: int

# T = TypeVar("T")
# def from_dict(data_class: Type[T], data: Data, config: Optional[Config] = None) -> T:

make = safe(from_dict)
Bob = make(Person, {"name": "Bob", "age": "35"})
#          ^^^^^^
# Argument 1 to "make" has incompatible type "Type[Person]"; expected "Type[T]" mypy(error)

dacite creates data classes from dicts.
from_dict function
https://github.com/konradhalas/dacite/blob/eae039bd25b2d0415de8e0d37cd07aca6c481c5c/dacite/core.py#L34

How is that should be

There is no errors without safe wrapper

System information

  • python version: 3.10.3

  • returns version: 0.19.0

  • mypy version: 0.942

  • hypothesis version (if any): -

  • pytest version (if any): -

Apparently the issue is because of Python 3.10. On the main page of dacite repository the latest tested version of Python is 39
konradhalas/dacite#167

Checked with 3.9 - mypy reports no errors.

  • python version: 3.9.12
  • returns version 0.19.0
  • mypy version 0.950

Checked with 3.10.4 - mypy reports no errors.

  • python version: 3.10.4
  • returns version 0.19.0
  • mypy version 0.950