From 73c68ad8ef5c8f6eb2aa9a7aaa809ecad7198c88 Mon Sep 17 00:00:00 2001 From: Tommy Smith Date: Tue, 30 Jan 2024 23:21:18 +0000 Subject: [PATCH] fix static typing --- weaviate/collections/classes/internal.py | 10 +--------- weaviate/collections/classes/types.py | 6 +++--- weaviate/collections/collection.py | 2 +- weaviate/collections/queries/base.py | 12 ++++++------ 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/weaviate/collections/classes/internal.py b/weaviate/collections/classes/internal.py index ed66d7d56..0671d7096 100644 --- a/weaviate/collections/classes/internal.py +++ b/weaviate/collections/classes/internal.py @@ -581,16 +581,13 @@ def from_input( GenerativeGroupByReturnType[Properties, References, TProperties, TReferences], ] -QueryReturnWithoutVectors = Union[ +QueryReturnType = Union[ QueryReturn[Properties, References, None], QueryReturn[TProperties, TReferences, None], QueryReturn[Properties, CrossReferences, None], QueryReturn[Properties, TReferences, None], QueryReturn[TProperties, References, None], QueryReturn[TProperties, CrossReferences, None], -] - -QueryReturnWithVectors = Union[ QueryReturn[Properties, References, Vectors], QueryReturn[TProperties, TReferences, Vectors], QueryReturn[Properties, CrossReferences, Vectors], @@ -599,11 +596,6 @@ def from_input( QueryReturn[TProperties, CrossReferences, Vectors], ] -QueryReturnType = Union[ - QueryReturnWithoutVectors[Properties, References, TProperties, TReferences], - QueryReturnWithVectors[Properties, References, TProperties, TReferences], -] - GroupByReturnType = Union[ GroupByReturn[Properties, References, None], GroupByReturn[Properties, References, Vectors], diff --git a/weaviate/collections/classes/types.py b/weaviate/collections/classes/types.py index 411d82e4d..253b961c7 100644 --- a/weaviate/collections/classes/types.py +++ b/weaviate/collections/classes/types.py @@ -102,10 +102,10 @@ class _PhoneNumber(_PhoneNumberBase): M = TypeVar("M") """`M` is a completely general type that is used wherever generic metadata objects are defined that can be used""" -V = TypeVar("V") +V = TypeVar("V", covariant=True) """`V` is a completely general type that is used wherever generic vector objects are defined that can be used""" -P = TypeVar("P") +P = TypeVar("P", covariant=True) """`P` is a completely general type that is used wherever generic properties objects are defined that can be used within the non-ORM and ORM APIs interchangeably""" @@ -113,7 +113,7 @@ class _PhoneNumber(_PhoneNumberBase): """`QP` is a completely general type that is used wherever generic properties objects are defined that can be used within the non-ORM and ORM APIs interchangeably""" -R = TypeVar("R") +R = TypeVar("R", covariant=True) """`R` is a completely general type that is used wherever generic reference objects are defined that can be used within the non-ORM and ORM APIs interchangeably""" diff --git a/weaviate/collections/collection.py b/weaviate/collections/collection.py index 2b28611d3..c8fa25033 100644 --- a/weaviate/collections/collection.py +++ b/weaviate/collections/collection.py @@ -387,8 +387,8 @@ def iterator( def iterator( self, *, - include_vector: bool = False, return_metadata: Optional[METADATA] = None, + include_vector: bool = False, return_properties: Optional[ReturnProperties[TProperties]] = None, return_references: Optional[ReturnReferences[TReferences]] = None, ) -> ObjectIterator[Properties, References, TProperties, TReferences]: diff --git a/weaviate/collections/queries/base.py b/weaviate/collections/queries/base.py index c5122efbb..3f3dfcb0b 100644 --- a/weaviate/collections/queries/base.py +++ b/weaviate/collections/queries/base.py @@ -258,7 +258,7 @@ def __result_to_generative_object( props: search_get_pb2.PropertiesResult, meta: search_get_pb2.MetadataResult, options: _QueryOptions, - ) -> GenerativeObject[Any, Any, Optional[Vectors]]: + ) -> GenerativeObject[Any, Any, Any]: return GenerativeObject( collection=props.target_collection, properties=( @@ -283,7 +283,7 @@ def __result_to_group( self, res: search_get_pb2.GroupByResult, options: _QueryOptions, - ) -> Group[Any, Any, Optional[Vectors]]: + ) -> Group[Any, Any, Any]: return Group( objects=[ self.__result_to_group_by_object(obj.properties, obj.metadata, options) @@ -300,7 +300,7 @@ def __result_to_generative_group( self, res: search_get_pb2.GroupByResult, options: _QueryOptions, - ) -> GenerativeGroup[Any, Any, Optional[Vectors]]: + ) -> GenerativeGroup[Any, Any, Any]: return GenerativeGroup( objects=[ self.__result_to_group_by_object(obj.properties, obj.metadata, options) @@ -319,7 +319,7 @@ def __result_to_group_by_object( props: search_get_pb2.PropertiesResult, meta: search_get_pb2.MetadataResult, options: _QueryOptions, - ) -> GroupedObject[Any, Any, Optional[Vectors]]: + ) -> GroupedObject[Any, Any, Any]: return GroupedObject( collection=props.target_collection, properties=( @@ -350,7 +350,7 @@ def _result_to_query_return( ReturnReferences[TReferences] ], # required until 3.12 is minimum supported version to use new generics syntax ) -> QueryReturnType[Properties, References, TProperties, TReferences]: - return QueryReturn( # type: ignore # used internally so types not important + return QueryReturn( # type: ignore objects=[ self.__result_to_query_object(obj.properties, obj.metadata, options) for obj in res.results @@ -368,7 +368,7 @@ def _result_to_generative_query_return( ReturnReferences[TReferences] ], # required until 3.12 is minimum supported version to use new generics syntax ) -> GenerativeReturnType[Properties, References, TProperties, TReferences]: - return GenerativeReturn( # type: ignore # used internally so types not important + return GenerativeReturn( objects=[ self.__result_to_generative_object(obj.properties, obj.metadata, options) for obj in res.results