22from collections .abc import Mapping , Sequence
33from datetime import datetime , timedelta , timezone
44from http import HTTPStatus
5- from typing import Any , Generic , Literal , overload
5+ from typing import Any , Generic , Literal , cast , overload
66from warnings import warn
77
88import msgspec
@@ -34,13 +34,38 @@ class AsyncBase(Generic[ItemT]):
3434 EXPIRES_ATTRIBUTE = "__expires"
3535 PUT_LIMIT = 30
3636
37+ @overload
38+ def __init__ (
39+ self : "AsyncBase[dict[str, Any]]" ,
40+ name : str ,
41+ / ,
42+ * ,
43+ data_key : str | None = None ,
44+ project_id : str | None = None ,
45+ host : str | None = None ,
46+ api_version : str = "v1" ,
47+ ) -> None : ...
48+
49+ @overload
50+ @deprecated ("The `project_key` parameter has been renamed to `data_key`." )
51+ def __init__ (
52+ self : "AsyncBase[dict[str, Any]]" ,
53+ name : str ,
54+ / ,
55+ * ,
56+ project_key : str | None = None ,
57+ project_id : str | None = None ,
58+ host : str | None = None ,
59+ api_version : str = "v1" ,
60+ ) -> None : ...
61+
3762 @overload
3863 def __init__ (
3964 self ,
4065 name : str ,
4166 / ,
4267 * ,
43- item_type : type [ItemT ] = Mapping [ str , Any ] ,
68+ item_type : type [ItemT ],
4469 data_key : str | None = None ,
4570 project_id : str | None = None ,
4671 host : str | None = None ,
@@ -54,7 +79,7 @@ def __init__(
5479 name : str ,
5580 / ,
5681 * ,
57- item_type : type [ItemT ] = Mapping [ str , Any ] ,
82+ item_type : type [ItemT ],
5883 project_key : str | None = None ,
5984 project_id : str | None = None ,
6085 host : str | None = None ,
@@ -66,7 +91,7 @@ def __init__( # noqa: PLR0913
6691 name : str ,
6792 / ,
6893 * ,
69- item_type : type [ItemT ] = Mapping [ str , Any ] ,
94+ item_type : type [ItemT ] | None = None ,
7095 data_key : str | None = None ,
7196 project_key : str | None = None , # Deprecated.
7297 project_id : str | None = None ,
@@ -78,7 +103,7 @@ def __init__( # noqa: PLR0913
78103 raise ValueError (msg )
79104
80105 self .name = name
81- self .item_type = item_type
106+ self .item_type = cast ( "type[ItemT]" , item_type if item_type is not None else dict [ str , Any ])
82107 self .data_key = data_key or project_key or get_data_key ()
83108 self .project_id = project_id or get_project_id ()
84109 self .host = host or os .getenv ("CONTIGUITY_BASE_HOST" ) or "api.base.contiguity.co"
@@ -118,7 +143,7 @@ def _response_as_item_type(
118143 response .raise_for_status ()
119144 except HTTPStatusError as exc :
120145 raise ContiguityApiError (exc .response .text ) from exc
121- return msgspec .json .decode (response .content , type = Sequence [self .item_type ] if sequence else self .item_type )
146+ return msgspec .json .decode (response .content , type = Sequence [self .item_type ] if sequence else self .item_type ) # ty: ignore[invalid-type-form]
122147
123148 def _insert_expires_attr (
124149 self ,
@@ -288,7 +313,7 @@ async def query(
288313 response .raise_for_status ()
289314 except HTTPStatusError as exc :
290315 raise ContiguityApiError (exc .response .text ) from exc
291- return msgspec .json .decode (response .content , type = QueryResponse [self .item_type ])
316+ return msgspec .json .decode (response .content , type = QueryResponse [self .item_type ]) # ty: ignore[invalid-type-form]
292317
293318 @deprecated ("This method has been renamed to `query` and will be removed in a future release." )
294319 async def fetch (
0 commit comments