1+ from typing import Tuple
12from .filter import Filter
23from .request_options import RequestOptions
34from .sort import Sort
45import math
56
67
7- def to_camel_case (word ) :
8+ def to_camel_case (word : str ) -> str :
89 return word .split ("_" )[0 ] + "" .join (x .capitalize () or "_" for x in word .split ("_" )[1 :])
910
1011
@@ -85,18 +86,21 @@ def _fetch_all(self):
8586 if self ._result_cache is None :
8687 self ._result_cache , self ._pagination_item = self .model .get (self .request_options )
8788
89+ def __len__ (self ) -> int :
90+ return self .total_available
91+
8892 @property
89- def total_available (self ):
93+ def total_available (self ) -> int :
9094 self ._fetch_all ()
9195 return self ._pagination_item .total_available
9296
9397 @property
94- def page_number (self ):
98+ def page_number (self ) -> int :
9599 self ._fetch_all ()
96100 return self ._pagination_item .page_number
97101
98102 @property
99- def page_size (self ):
103+ def page_size (self ) -> int :
100104 self ._fetch_all ()
101105 return self ._pagination_item .page_size
102106
@@ -121,7 +125,7 @@ def paginate(self, **kwargs):
121125 self .request_options .pagesize = kwargs ["page_size" ]
122126 return self
123127
124- def _parse_shorthand_filter (self , key ) :
128+ def _parse_shorthand_filter (self , key : str ) -> Tuple [ str , str ] :
125129 tokens = key .split ("__" , 1 )
126130 if len (tokens ) == 1 :
127131 operator = RequestOptions .Operator .Equals
@@ -135,7 +139,7 @@ def _parse_shorthand_filter(self, key):
135139 raise ValueError ("Field name `{}` is not valid." .format (field ))
136140 return (field , operator )
137141
138- def _parse_shorthand_sort (self , key ) :
142+ def _parse_shorthand_sort (self , key : str ) -> Tuple [ str , str ] :
139143 direction = RequestOptions .Direction .Asc
140144 if key .startswith ("-" ):
141145 direction = RequestOptions .Direction .Desc
0 commit comments