jayceslesar commented on issue #2160:
URL:
https://github.com/apache/iceberg-python/issues/2160#issuecomment-3016761060
Nice, yeah looks like we can do something like
```py
from typing import Any, Literal
from pydantic import BaseModel, Field, field_validator
class MyModel(BaseModel):
my_literal: Literal[1] = Field(alias="my-literal")
@field_validator("my_literal", mode="before")
def validate_my_literal(cls, v: Any) -> int:
"""Validate that my_literal is 1 for MyModel."""
if v != 1:
raise ValueError(f"MyModel requires my-literal to be 1, got {v}")
return v
MyModel(**{"my-literal": 2})
```
Which raises
```
pydantic_core._pydantic_core.ValidationError: 1 validation error for MyModel
my-literal
Value error, MyModel requires my-literal to be 1, got 2 [type=value_error,
input_value=2, input_type=int]
For further information visit
https://errors.pydantic.dev/2.11/v/value_error
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]