Skip to content

Bug: fields API does not support generic Structs if the type is specified #570

Closed

Description

@vkcku

Description

The msgspec.structs.fields API does not support generic types if the type is specified as seen below:

from typing import Generic, TypeVar

from msgspec import Struct
from msgspec.structs import fields

T = TypeVar("T")


class GenericFoo(Struct, Generic[T]):
    foo: T


generic_foo_fields = fields(GenericFoo)  # does not fail
generic_foo_fields = fields(GenericFoo[int])  # fails

The reason for this is that isinstance(GenericFoo[int], type) will return False.

Activity

  1. jcrist commented on Oct 17, 2023

    @jcrist
    Member

    Thanks for the issue, this is resolved in #571.

  2. vkcku commented on Oct 18, 2023

    @vkcku
    Author

    Thank you so much for such fast fixes :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions