Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support Literal[bool] #859

Description

@peku33

Description

Many APIs use something like {"success": true, data: ...}.

It will be really nice to be able to validate such boolean field against constant value when deserializing:

from typing import Literal

import msgspec


class ResponseData(msgspec.Struct):
    pass


class Response(msgspec.Struct):
    success: Literal[True]
    data: ResponseData


response = msgspec.convert(
    {
        "success": True,
        "data": {},
    },
    Response,
)

At the moment this raises:

TypeError: Literal may only contain None/integers/strings - typing.Literal[True] is not supported

Thank you 👍

Activity

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