Skip to content

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

@dwt

Description

@dwt

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. :/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions