1111type RowAttribute = bool | int | str | datetime | UUID | StrEnum
1212
1313
14- @dataclass (frozen = True )
15- class RowSchema (Sequence [type [RowAttribute ]]):
16- name : str
17- id_type : type [RowAttribute ]
18- body_types : tuple [type [RowAttribute ], ...] = tuple ()
19-
20- def __iter__ (self ) -> Iterator [type [RowAttribute ]]:
21- yield self .id_type
22- yield from self .body_types
23-
24- @overload
25- def __getitem__ (self , index : int , / ) -> type [RowAttribute ]: ...
26-
27- @overload
28- def __getitem__ (
29- self , slice_ : "slice[Any, Any, Any]" , /
30- ) -> Sequence [type [RowAttribute ]]: ...
31-
32- def __getitem__ (
33- self , value : "int | slice[Any, Any, Any]" , /
34- ) -> Sequence [type [RowAttribute ]] | type [RowAttribute ]:
35- return tuple (self )[value ]
36-
37- def __len__ (self ) -> int :
38- return len (self .body_types ) + 1
39-
40-
41- class RowSchemaError (Exception ):
42- def __init__ (self , schema : RowSchema ) -> None :
43- self .schema = schema
44- super ().__init__ ()
45-
46-
4714@dataclass (frozen = True )
4815class Row (IdentifiedValue [RowAttribute ], Sequence [RowAttribute ]):
4916 body : tuple [RowAttribute , ...]
50- schema : RowSchema
51-
52- def __post_init__ (self ) -> None :
53- for attribute_and_type in zip (self , self .schema , strict = False ):
54- if len (attribute_and_type ) != 2 :
55- raise RowSchemaError (self .schema )
56-
57- attribute , type = attribute_and_type
58-
59- if not isinstance (attribute , type ):
60- raise RowSchemaError (self .schema )
6117
6218 def __iter__ (self ) -> Iterator [RowAttribute ]:
6319 yield self .id
@@ -80,4 +36,8 @@ def __len__(self) -> int:
8036 return len (self .body ) + 1
8137
8238
39+ def row (* attrs : RowAttribute ) -> Row :
40+ return Row (attrs [0 ], attrs [1 :])
41+
42+
8343type RowEffect = New [Row ] | Mutated [Row ] | Dead [Row ]
0 commit comments