Skip to content

Commit

Permalink
Update datetime.datetime.utcnow() to datetime.datetime.now(datetime.t…
Browse files Browse the repository at this point in the history
…imezone.utc) (#111)

* update datetime.datetime.utcnow() to datetime.datetime.now(datetime.timezone.utc)

* run ruff
  • Loading branch information
parkerhancock authored Nov 18, 2023
1 parent 893690f commit 6885a34
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Fix issue where freshness cannot be calculated to re-send request. (#104)
- Update `datetime.datetime.utcnow()` to `datetime.datetime.now(datetime.timezone.utc)` since `datetime.datetime.utcnow()` has been deprecated. (#111)

## 0.0.17 (6/11/2023)

Expand Down
4 changes: 3 additions & 1 deletion hishel/_async/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ async def handle_async_request(self, request: Request) -> Response:

if self._controller.is_cachable(request=request, response=response):
await response.aread()
metadata = Metadata(cache_key=key, created_at=datetime.datetime.utcnow(), number_of_uses=0)
metadata = Metadata(
cache_key=key, created_at=datetime.datetime.now(datetime.timezone.utc), number_of_uses=0
)
await self._storage.store(key, response=response, request=request, metadata=metadata)

response.extensions["from_cache"] = False # type: ignore[index]
Expand Down
4 changes: 3 additions & 1 deletion hishel/_async/_transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ async def handle_async_request(self, request: Request) -> Response:
await httpcore_response.aclose()

if self._controller.is_cachable(request=httpcore_request, response=httpcore_response):
metadata = Metadata(cache_key=key, created_at=datetime.datetime.utcnow(), number_of_uses=0)
metadata = Metadata(
cache_key=key, created_at=datetime.datetime.now(datetime.timezone.utc), number_of_uses=0
)
await self._storage.store(
key,
response=httpcore_response,
Expand Down
2 changes: 1 addition & 1 deletion hishel/_sync/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def handle_request(self, request: Request) -> Response:

if self._controller.is_cachable(request=request, response=response):
response.read()
metadata = Metadata(cache_key=key, created_at=datetime.datetime.utcnow(), number_of_uses=0)
metadata = Metadata(cache_key=key, created_at=datetime.datetime.now(datetime.timezone.utc), number_of_uses=0)
self._storage.store(key, response=response, request=request, metadata=metadata)

response.extensions["from_cache"] = False # type: ignore[index]
Expand Down
2 changes: 1 addition & 1 deletion hishel/_sync/_transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def handle_request(self, request: Request) -> Response:
httpcore_response.close()

if self._controller.is_cachable(request=httpcore_request, response=httpcore_response):
metadata = Metadata(cache_key=key, created_at=datetime.datetime.utcnow(), number_of_uses=0)
metadata = Metadata(cache_key=key, created_at=datetime.datetime.now(datetime.timezone.utc), number_of_uses=0)
self._storage.store(
key,
response=httpcore_response,
Expand Down
2 changes: 1 addition & 1 deletion tests/_async/test_storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from hishel._serializers import Metadata
from hishel._utils import asleep, generate_key

dummy_metadata = Metadata(cache_key="test", number_of_uses=0, created_at=datetime.datetime.utcnow())
dummy_metadata = Metadata(cache_key="test", number_of_uses=0, created_at=datetime.datetime.now(datetime.timezone.utc))


async def is_redis_down() -> bool:
Expand Down
2 changes: 1 addition & 1 deletion tests/_sync/test_storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from hishel._serializers import Metadata
from hishel._utils import sleep, generate_key

dummy_metadata = Metadata(cache_key="test", number_of_uses=0, created_at=datetime.datetime.utcnow())
dummy_metadata = Metadata(cache_key="test", number_of_uses=0, created_at=datetime.datetime.now(datetime.timezone.utc))


def is_redis_down() -> bool:
Expand Down

0 comments on commit 6885a34

Please sign in to comment.