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

Pylance says Cannot access member "schema" for type "Type[...]" #309

Open
davetapley opened this issue Aug 19, 2021 · 3 comments
Open

Pylance says Cannot access member "schema" for type "Type[...]" #309

davetapley opened this issue Aug 19, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@davetapley
Copy link

I have this snippet in VSCode with Python 3.9.6 and Pylance (v2021.8.1105858891):

@dataclass_json
@dataclass
class Folder:
    Id: int
    Name: str

# mode code

        return Folder.schema().load(res.json()['Folders'], many=True)

And Pylance is underlining schema in red, saying:

Cannot access member "schema" for type "Type[Folder]"
  Member "schema" is unknownPylancereportGeneralTypeIssues

I'm opening here instead of against Pylance to see if others are seeing this, and just in case something it's something with ⬇️ which is confusing/breaking Pylance 🤔

def schema(cls: Type[A],

@bentheadset
Copy link

bentheadset commented Jan 31, 2022

It appears to me that pylance is struggling with certain uses methods on @dataclass classes.

For instance, in some circumstances:

from my_module import MyBaseClass

@dataclass
class` Foo(MyBaseClass):
    a: int
    def foo(self):
        print("...")

def bar() -> Foo:
    return Foo(a=0)

bar().foo()   # <-- pylance error

pylance will flag foo() call, "Cannot access member "foo" for type "Dataclass"

I haven't had time to verify if this is related to

  • the type hints (error mentions Dataclass NOT the udt),
  • or the MRO or other inheritence issue (if I remove the inheritance from MyBaseClass, pylance accepts the code)
    • note, perhaps NOT similar to @davetapley 's reproduction, as @dataclass_json is not altering MRO but rather just adds cls attrs

@lidatong
Copy link
Owner

this is probably a general problem of visibility of the class decorator to static type checkers -- i've begun looking into various solutions for this

@lidatong lidatong added the bug Something isn't working label Jan 31, 2022
@george-zubrienko
Copy link
Collaborator

Should be fixed as a result of #442 work - with a breaking change most likely

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

4 participants