konradhalas / dacite

Simple creation of data classes from dictionaries.
MIT License
1.72k stars 106 forks source link

Regression in recognizing the type of the dataclass in case of inheritance #231

Open redlickigrzegorz opened 1 year ago

redlickigrzegorz commented 1 year ago

Describe the bug According to the example I posted below, dacite provides information that the returned object is a Base instance, not a User. At least that's how it looks from a pylint perspective (mypy doesn't report any errors). Technically, the code below still works, but there were no warnings/errors when version 1.7.0 was used.

To Reproduce

from __future__ import annotations

from dataclasses import dataclass
from typing import Type, TypeVar

from dacite import from_dict
from dacite.data import Data

T = TypeVar("T")

@dataclass
class Base:
    @classmethod
    def from_dict(cls: Type[T], data: Data) -> T:
        return from_dict(data_class=cls, data=data)

@dataclass
class User(Base):
    name: str

user = User.from_dict({"name": "John"})

print(user.name)  # E1101: Instance of 'Base' has no 'name' member (no-member)

Expected behavior No pylint errors as it was in version 1.7.0.

Environment

Additional context We implemented such a "base" dataclass a long time ago. And maybe it is not the best piece of the code but it forces us to use the from_dict() function always the same way, no matter which class we talk about (consistency).

In the near future, we plan to upgrade our code to Python 3.11, then, I will verify it once again. But if I find some free time for open-source coding in the meantime, I will try to debug it on my own 😉

pdyba commented 7 months ago

With python 3.12 and newest pylint the issue persists. 1.7.0 was also last fully working version for me.