requests-cache / aiohttp-client-cache

An async persistent cache for aiohttp requests
MIT License
118 stars 20 forks source link

`datetime.utcnow` is deprecated #237

Closed layday closed 4 months ago

layday commented 5 months ago

Hi, just a heads-up that datetime.utcnow was deprecated in Python 3.12. datetime.utcnow is used in several places in aiohttp-client-cache. The Python documentation recommends creating tz-aware datetime objects instead; a semantic equivalent would be datetime.utc(timezone.utc).replace(tzinfo=None), if you'd like to keep working with "naive" datetimes instead.

jamesbraza commented 5 months ago

+1 to this. To share the full DeprecationWarning:

/path/to/lib/python3.12/site-packages/aiohttp_client_cache/response.py:159: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).

To filter this out with pytest:

# pyproject.toml

[tool.pytest.ini_options]
filterwarnings = [
    'ignore:datetime.datetime.utcnow\(\) is deprecated and scheduled for removal in a future version:DeprecationWarning:aiohttp_client_cache',  # SEE: https://github.com/requests-cache/aiohttp-client-cache/issues/237
]