marshmallow_dataclass icon indicating copy to clipboard operation
marshmallow_dataclass copied to clipboard

PyRight: Static TypeChecking of `Schema: ClassVar[Type[Schema]] = Schema` fail

Open dwt opened this issue 1 year ago • 0 comments

Hi there,

not quite sure what is going on, but this code doesn't type check for me in the Zed Editor.

# excerpt
from dataclasses import field
from typing import ClassVar, Type

import marshmallow as mm
from marshmallow_dataclass import dataclass

from controller.process_distribution.models import Document, Partner


@dataclass
class PostverteilungInput:
    Schema: ClassVar[Type[mm.Schema]] = mm.Schema

    partner: list[Partner] = field(
        metadata={
            "validate": mm.validate.Length(min=1),
            "required": True,
        },
    )
    dokument: Document = field(
        metadata={"required": True},
    )
    geschuetzt: bool = field(metadata={"required": True}, default=False)
image

Putting the Schema variable as Schema: ClassVar[Type[mm.Schema]] also doesn't help.

Shouldn't this type check? It seems that the type is insofar wrong, as mm.Schema.load() does indeed not return the class PostverteilungInput but only Unknown | list[Unknown] | dict[Unknown, Unknown] | None. But this seems to be what the documentation recommends.

It seems I am missing something about how the typing is supposed to work here. :/

dwt avatar Aug 23 '24 12:08 dwt