Skip to content

Commit 0d9b8e6

Browse files
authored
Fix type stubs for Model.count (pynamodb#587)
1 parent a762e5e commit 0d9b8e6

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

pynamodb/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ def count(cls,
546546
:param filter_condition: Condition used to restrict the query results
547547
:param consistent_read: If True, a consistent read is performed
548548
:param index_name: If set, then this index is used
549+
:param rate_limit: If set then consumed capacity will be limited to this amount per second
549550
:param filters: A dictionary of filters to be used in the query. Requires a hash_key to be passed.
550551
"""
551552
if hash_key is None:

pynamodb/models.pyi

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,17 @@ class Model(metaclass=MetaModel):
4343
@classmethod
4444
def from_raw_data(cls: Type[_T], data) -> _T: ...
4545
@classmethod
46-
def count(cls: Type[_T], hash_key: Optional[KeyType] = ..., consistent_read: bool = ..., index_name: Optional[Text] = ..., limit: Optional[int] = ..., **filters) -> int: ...
46+
def count(
47+
cls: Type[_T],
48+
hash_key: Optional[KeyType] = ...,
49+
range_key_condition: Optional[Condition] = ...,
50+
filter_condition: Optional[Condition] = ...,
51+
consistent_read: bool = ...,
52+
index_name: Optional[Text] = ...,
53+
limit: Optional[int] = ...,
54+
rate_limit: Optional[float] = ...,
55+
**filters
56+
) -> int: ...
4757
@classmethod
4858
def query(
4959
cls: Type[_T],

pynamodb/tests/test_mypy.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
from .mypy_helpers import assert_mypy_output # noqa
1010

1111

12+
def test_model():
13+
assert_mypy_output("""
14+
from pynamodb.models import Model
15+
from pynamodb.expressions.operand import Path
16+
17+
class MyModel(Model):
18+
pass
19+
20+
reveal_type(MyModel.count('hash', Path('a').between(1, 3))) # E: Revealed type is 'builtins.int'
21+
""")
22+
23+
1224
def test_number_attribute():
1325
assert_mypy_output("""
1426
from pynamodb.attributes import NumberAttribute

0 commit comments

Comments
 (0)