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

VSCode Intellisense error for pydantic dataclasses #4014

Closed
jgrugru opened this issue Apr 27, 2022 · 2 comments
Closed

VSCode Intellisense error for pydantic dataclasses #4014

jgrugru opened this issue Apr 27, 2022 · 2 comments
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@jgrugru
Copy link

jgrugru commented Apr 27, 2022

I am receiving an intellisense error on an inherited pydantic dataclass. I was able to replicate this on two operating systems, one in VSCode, the other in pycharm.

You can replicate the intellisense error with this snippet:

from abc import ABC, abstractmethod
from pydantic import BaseModel, dataclasses
from typing import List

# python --version -> Python 3.10.2
# pydantic=1.9.0
# Running on MacOS Monterey 12.3.1


@dataclasses.dataclass(frozen=True, eq=True)
class PersonABC(ABC):
    name: str

    @abstractmethod
    def print_bio(self):
        pass

@dataclasses.dataclass(frozen=True, eq=True)
class Jeff(PersonABC):
    age: int

    def print_bio(self):
        print(f"{self.name}: {self.age}")     # In VScode, self.name is not registered as a known variable:
                                              # `Cannot access member "name" for type "Jeff"
                                              # Member "name" is unknownPylancereportGeneralTypeIssues`

class Family(BaseModel):
    person: List[PersonABC]


jeff = Jeff(name="Jeff Gruenbaum", age=93)
print(Family(person=[jeff]))

The error takes place in the implemented print_bio function. The full error is in the comments above.

@jgrugru jgrugru added the bug V1 Bug related to Pydantic V1.X label Apr 27, 2022
@samuelcolvin
Copy link
Member

is this fixed by #4007?

@jgrugru
Copy link
Author

jgrugru commented May 15, 2022

@samuelcolvin Yes, looks like #4007 resolves this issue, closing this issue.

@jgrugru jgrugru closed this as completed May 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X
Projects
None yet
Development

No branches or pull requests

2 participants