dataclasses-json
dataclasses-json copied to clipboard
Pylance says Cannot access member "schema" for type "Type[...]"
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 🤔
https://github.com/lidatong/dataclasses-json/blob/3dc59e01ccdfec619ee4e4c3502b9759b67c3fa8/dataclasses_json/api.py#L89
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 mentionsDataclassNOT theudt), - or the
MROor other inheritence issue (if I remove the inheritance fromMyBaseClass, pylance accepts the code)- note, perhaps NOT similar to @davetapley 's reproduction, as
@dataclass_jsonis not alteringMRObut rather just addsclsattrs
- note, perhaps NOT similar to @davetapley 's reproduction, as
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
Should be fixed as a result of #442 work - with a breaking change most likely