I'm using the Pylance extension in VS Code, and I encountered a warning Variable not allowed in type expression. It seems that Pylance is not recognizing an imported class when used in a type expression.
Here is a simplified version of my code:
from dataclasses import dataclass
from typing import ClassVar
from marshmallow import Schema
from marshmallow_dataclass import add_schema
@add_schema
@dataclass(frozen=True)
class A:
name: str
Schema: ClassVar[type[Schema]] = Schema
A().Schema().load()
Pylance thinks that Schema used in type[Schema] is a variable name, not the imported class. If I use from __future__ import annotations - the warning disappears. And I want to resolve it so that I have useful highlights and code completion when the Schema is loaded.