Skip to content

Commit

Permalink
typing: Timestamp*Attributes in actions and conditions (#18)
Browse files Browse the repository at this point in the history
Allow using Timestamp*Attributes in actions and conditions.
  • Loading branch information
Ilya Konstantinov authored Jul 6, 2020
1 parent aaed8d6 commit 15e9b28
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
9 changes: 3 additions & 6 deletions pynamodb_attributes/timestamp.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ from ._typing import Attribute


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


class TimestampMsAttribute(TimestampAttribute):
def __get__(self, instance: Any, owner: Any) -> datetime: ...
def __set__(self, instance: Any, value: datetime) -> None: ...
...


class TimestampUsAttribute(TimestampAttribute):
def __get__(self, instance: Any, owner: Any) -> datetime: ...
def __set__(self, instance: Any, value: datetime) -> None: ...
...
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def find_stubs(package): # type: ignore

setup(
name='pynamodb-attributes',
version='0.2.7',
version='0.2.8',
description='Common attributes for PynamoDB',
url='https://www.github.com/lyft/pynamodb-attributes',
maintainer='Lyft',
Expand Down
17 changes: 10 additions & 7 deletions tests/mypy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class MyModel(Model):

def test_timestamp_attribute():
assert_mypy_output("""
from datetime import datetime
from pynamodb.models import Model
from pynamodb_attributes import TimestampAttribute, TimestampMsAttribute, TimestampUsAttribute
Expand All @@ -82,13 +83,15 @@ class MyModel(Model):
ts_us = TimestampUsAttribute()
m = MyModel()
reveal_type(m.ts) # E: Revealed type is 'datetime.datetime'
reveal_type(m.ts_ms) # E: Revealed type is 'datetime.datetime'
reveal_type(m.ts_us) # E: Revealed type is 'datetime.datetime'
m.ts = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "datetime")
m.ts_ms = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "datetime")
m.ts_us = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "datetime")
""")
reveal_type(m.ts) # E: Revealed type is 'datetime.datetime*'
reveal_type(m.ts_ms) # E: Revealed type is 'datetime.datetime*'
reveal_type(m.ts_us) # E: Revealed type is 'datetime.datetime*'
m.ts = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "Optional[datetime]")
m.ts_ms = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "Optional[datetime]")
m.ts_us = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "Optional[datetime]")
m.save(condition=MyModel.ts == datetime.now())
""") # noqa: E501


def test_uuid_attribute():
Expand Down

0 comments on commit 15e9b28

Please sign in to comment.