Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
redlickigrzegorz opened this issue May 15, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@redlickigrzegorz
Copy link

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

  • Python version: 3.8.10
  • dacite version: 1.8.1
  • pylint version: 2.17.4

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 😉

@redlickigrzegorz redlickigrzegorz added the bug Something isn't working label May 15, 2023
@pdyba
Copy link

pdyba commented Jan 24, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants