Pydantic annotations using instance attributes seem to be ignored
Benezivas opened this issue · 0 comments
Benezivas commented
We have designed a problem for packing a 2D Knapsack as full as possible. Here is a snippet from the problem.py
:
Number = SizeIndex
lengthItem = Annotated[int, Interval(ge=1, le=InstanceRef.length)]
widthItem = Annotated[int, Interval(ge=1, le=InstanceRef.width)]
Point = tuple[lengthItem, widthItem]
lengthPosition = Annotated[int, Interval(ge=0, lt=InstanceRef.length)]
widthPosition = Annotated[int, Interval(ge=0, lt=InstanceRef.width)]
rotation = Literal["unrotated", "rotated"]
class Instance(InstanceModel):
"""An instance of a 2dKnapsack problem."""
length: u64 = Field(ge=1)
width: u64 = Field(ge=1)
items: list[Point]
@property
def size(self) -> int:
return len(self.items)
Do note the items
attribute: It is defined as a list of Point
s, which themselves are a tuple with members lengthItem
and widthItem
. These two members are defined to each be in an interval between 1
and InstanceRef.length
.
This last guard seems to be completely ignored. Students are able to pass item
s such as (0,0)
and to exceed the implicit guard of u64
, of length
and width
.
Is this a problem of the concrete way we annotated these attributes?