3737from .._items import ItemList
3838from ..repr import object_repr
3939from ..types import ID , Column
40- from ._keys import KL , GenericKey , K , create_key_type , key_dict , key_fields , project_key
40+ from ._keys import KL , GenericKey , create_key_type , key_dict , key_fields , project_key
4141
4242if TYPE_CHECKING :
4343 from .._dataset import Dataset
@@ -111,8 +111,20 @@ def __init__(self, key: type[KL] | Sequence[str]):
111111 else :
112112 self ._key_class = create_key_type (* key ) # type: ignore
113113
114+ @overload
115+ @staticmethod
116+ def empty [K : GenericKey ](
117+ key : type [K ], * , index : bool = True
118+ ) -> MutableItemListCollection [K ]: ...
119+ @overload
114120 @staticmethod
115- def empty (key : type [K ] | Sequence [str ], * , index : bool = True ) -> MutableItemListCollection [K ]:
121+ def empty (
122+ key : Sequence [str ], * , index : bool = True
123+ ) -> MutableItemListCollection [GenericKey ]: ...
124+ @staticmethod
125+ def empty [K : GenericKey ](
126+ key : type [K ] | Sequence [str ], * , index : bool = True
127+ ) -> MutableItemListCollection [K ]:
116128 """
117129 Create a new empty, mutable item list collection.
118130 """
@@ -122,7 +134,7 @@ def empty(key: type[K] | Sequence[str], *, index: bool = True) -> MutableItemLis
122134
123135 @overload
124136 @staticmethod
125- def from_dict (
137+ def from_dict [ K : GenericKey ] (
126138 data : Mapping [GenericKey | ID , ItemList ], key : type [K ]
127139 ) -> ItemListCollection [K ]: ...
128140 @overload
@@ -131,7 +143,7 @@ def from_dict(
131143 data : Mapping [GenericKey | ID , ItemList ], key : Sequence [str ] | str | None = None
132144 ) -> ItemListCollection [GenericKey ]: ...
133145 @staticmethod
134- def from_dict (
146+ def from_dict [ K : GenericKey ] (
135147 data : Mapping [GenericKey | ID , ItemList ],
136148 key : type [K ] | Sequence [str ] | str | None = None ,
137149 ) -> ItemListCollection [GenericKey ]:
@@ -147,7 +159,9 @@ def from_dict(
147159
148160 @staticmethod
149161 def from_df (
150- df : pd .DataFrame , key : type [K ] | Sequence [Column ] | Column | None = None , * others : Column
162+ df : pd .DataFrame ,
163+ key : type [GenericKey ] | Sequence [Column ] | Column | None = None ,
164+ * others : Column ,
151165 ) -> MutableItemListCollection [Any ]:
152166 """
153167 Create an item list collection from a data frame.
@@ -339,24 +353,24 @@ def load_parquet(
339353 path : PathLike [str ] | list [PathLike [str ]],
340354 * ,
341355 layout : Literal ["native" ] = "native" ,
342- ) -> ItemListCollection : ...
356+ ) -> ItemListCollection [ GenericKey ] : ...
343357 @overload
344358 @classmethod
345- def load_parquet (
359+ def load_parquet [ K : GenericKey ] (
346360 cls ,
347361 path : PathLike [str ] | list [PathLike [str ]],
348362 key : type [K ] | Sequence [Column ] | Column ,
349363 * ,
350364 layout : Literal ["flat" ],
351- ) -> ItemListCollection : ...
365+ ) -> ItemListCollection [ K ] : ...
352366 @classmethod
353- def load_parquet (
367+ def load_parquet [ K : GenericKey ] (
354368 cls ,
355369 path : PathLike [str ] | list [PathLike [str ]],
356370 key : type [K ] | Sequence [Column ] | Column | None = None ,
357371 * ,
358372 layout : Literal ["native" , "flat" ] = "native" ,
359- ) -> ItemListCollection :
373+ ) -> ItemListCollection [ GenericKey ] :
360374 """
361375 Load this item list from a Parquet file.
362376
@@ -577,7 +591,7 @@ def add_from(self, other: ItemListCollection, **fields: ID):
577591 raise NotImplementedError ()
578592
579593
580- class MutableItemListCollection ( ItemListCollector , ItemListCollection [ K ], Generic [K ]):
594+ class MutableItemListCollection [ K : GenericKey ]( ItemListCollector , ItemListCollection [K ]):
581595 """
582596 Intersection type of :class:`ItemListCollection` and
583597 :class:`ItemListCollector`.
0 commit comments