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

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

Open
dwt opened this issue Aug 23, 2024 · 0 comments
Open

Comments

@dwt
Copy link

dwt commented Aug 23, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant