|
32 | 32 | Union, |
33 | 33 | ) |
34 | 34 |
|
| 35 | +from pydantic import model_validator |
| 36 | + |
35 | 37 | from pyiceberg.expressions.literals import ( |
36 | 38 | AboveMax, |
37 | 39 | BelowMin, |
38 | 40 | Literal, |
39 | 41 | literal, |
40 | 42 | ) |
41 | 43 | from pyiceberg.schema import Accessor, Schema |
42 | | -from pyiceberg.typedef import L, StructProtocol |
| 44 | +from pyiceberg.typedef import IcebergBaseModel, L, StructProtocol |
43 | 45 | from pyiceberg.types import DoubleType, FloatType, NestedField |
44 | 46 | from pyiceberg.utils.singleton import Singleton |
45 | 47 |
|
@@ -329,21 +331,27 @@ def __getnewargs__(self) -> Tuple[BooleanExpression, BooleanExpression]: |
329 | 331 | return (self.left, self.right) |
330 | 332 |
|
331 | 333 |
|
332 | | -class Not(BooleanExpression): |
| 334 | +class Not(IcebergBaseModel, BooleanExpression): |
333 | 335 | """NOT operation expression - logical negation.""" |
334 | 336 |
|
335 | 337 | child: BooleanExpression |
336 | 338 |
|
337 | | - def __new__(cls, child: BooleanExpression) -> BooleanExpression: # type: ignore |
| 339 | + @model_validator(mode="before") |
| 340 | + def _before(cls, values: Any) -> Any: |
| 341 | + if isinstance(values, BooleanExpression): |
| 342 | + return {"child": values} |
| 343 | + return values |
| 344 | + |
| 345 | + @model_validator(mode="after") |
| 346 | + def _normalize(cls, model: Any) -> Any: |
| 347 | + child = model.child |
338 | 348 | if child is AlwaysTrue(): |
339 | 349 | return AlwaysFalse() |
340 | 350 | elif child is AlwaysFalse(): |
341 | 351 | return AlwaysTrue() |
342 | 352 | elif isinstance(child, Not): |
343 | 353 | return child.child |
344 | | - obj = super().__new__(cls) |
345 | | - obj.child = child |
346 | | - return obj |
| 354 | + return model |
347 | 355 |
|
348 | 356 | def __repr__(self) -> str: |
349 | 357 | """Return the string representation of the Not class.""" |
|
0 commit comments