Skip to content

Commit 15e9b28

Browse files
author
Ilya Konstantinov
authored
typing: Timestamp*Attributes in actions and conditions (#18)
Allow using Timestamp*Attributes in actions and conditions.
1 parent aaed8d6 commit 15e9b28

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

pynamodb_attributes/timestamp.pyi

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ from ._typing import Attribute
55

66

77
class TimestampAttribute(Attribute[datetime]):
8-
def __get__(self, instance: Any, owner: Any) -> datetime: ...
9-
def __set__(self, instance: Any, value: datetime) -> None: ...
8+
...
109

1110

1211
class TimestampMsAttribute(TimestampAttribute):
13-
def __get__(self, instance: Any, owner: Any) -> datetime: ...
14-
def __set__(self, instance: Any, value: datetime) -> None: ...
12+
...
1513

1614

1715
class TimestampUsAttribute(TimestampAttribute):
18-
def __get__(self, instance: Any, owner: Any) -> datetime: ...
19-
def __set__(self, instance: Any, value: datetime) -> None: ...
16+
...

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def find_stubs(package): # type: ignore
1616

1717
setup(
1818
name='pynamodb-attributes',
19-
version='0.2.7',
19+
version='0.2.8',
2020
description='Common attributes for PynamoDB',
2121
url='https://www.github.com/lyft/pynamodb-attributes',
2222
maintainer='Lyft',

tests/mypy_test.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class MyModel(Model):
7373

7474
def test_timestamp_attribute():
7575
assert_mypy_output("""
76+
from datetime import datetime
7677
from pynamodb.models import Model
7778
from pynamodb_attributes import TimestampAttribute, TimestampMsAttribute, TimestampUsAttribute
7879
@@ -82,13 +83,15 @@ class MyModel(Model):
8283
ts_us = TimestampUsAttribute()
8384
8485
m = MyModel()
85-
reveal_type(m.ts) # E: Revealed type is 'datetime.datetime'
86-
reveal_type(m.ts_ms) # E: Revealed type is 'datetime.datetime'
87-
reveal_type(m.ts_us) # E: Revealed type is 'datetime.datetime'
88-
m.ts = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "datetime")
89-
m.ts_ms = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "datetime")
90-
m.ts_us = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "datetime")
91-
""")
86+
reveal_type(m.ts) # E: Revealed type is 'datetime.datetime*'
87+
reveal_type(m.ts_ms) # E: Revealed type is 'datetime.datetime*'
88+
reveal_type(m.ts_us) # E: Revealed type is 'datetime.datetime*'
89+
m.ts = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "Optional[datetime]")
90+
m.ts_ms = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "Optional[datetime]")
91+
m.ts_us = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "Optional[datetime]")
92+
93+
m.save(condition=MyModel.ts == datetime.now())
94+
""") # noqa: E501
9295

9396

9497
def test_uuid_attribute():

0 commit comments

Comments
 (0)