We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Union
Suppose that an int field needs to be bound to some intervals:
int
from typing import Annotated import msgspec as ms LowerBounds = Annotated[int, ms.Meta(ge=-10, le=-1)] UpperBounds = Annotated[int, ms.Meta(ge=1, le=10)] class T(ms.Struct): n: LowerBounds | UpperBounds
As the docs state:
Unions may contain at most one type that encodes to an integer (int, enum.IntEnum)
enum.IntEnum
the following will then expectedly fail:
ms.json.decode('{"n":-1}', type=T) # msgspec.ValidationError: Expected `int` >= 1 - at `$.n`
Please consider lifting this restriction.
The text was updated successfully, but these errors were encountered:
I too require this feature for the following data type:
class Ok(Generic[A]): def __init__(self, value: A): self.value = value def to_json(self) -> JSON: return {"ok": self.value} def __bool__(self): return True class Err(Generic[A]): def __init__(self, value: A): self.value = value def to_json(self) -> JSON: return {"err": self.value} def __bool__(self): return False Result = Ok[A] | Err[B]
Sorry, something went wrong.
No branches or pull requests
Description
Suppose that an
int
field needs to be bound to some intervals:As the docs state:
the following will then expectedly fail:
Please consider lifting this restriction.
The text was updated successfully, but these errors were encountered: