sdispater / pendulum

Python datetimes made easy
https://pendulum.eustace.io
MIT License
6.21k stars 384 forks source link

DeprecationWarning about datetime.utcfromtimestamp in Python-3.12 #830

Open wosc opened 4 months ago

wosc commented 4 months ago

Issue

datetime.utcfromtimestamp() is used by pendulum.from_timestamp(), but it is deprecated starting in Python-3.12 (the stdlib docs say to use datetime.fromtimestamp(timestamp, tz=timezone.utc) instead):

$ python3.12 -W all
Python 3.12.3 (main, May 14 2024, 07:34:56) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pendulum
>>> pendulum.from_timestamp(1)
/usr/local/lib/python3.12/site-packages/pendulum/__init__.py:295: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
  dt = _datetime.datetime.utcfromtimestamp(timestamp)
DateTime(1970, 1, 1, 0, 0, 1, tzinfo=Timezone('UTC'))
henviso commented 4 weeks ago

Hello @edgarrmondragon.

Do you know if there was an answer for how to deal with this?

edgarrmondragon commented 4 weeks ago

Hello @edgarrmondragon.

Do you know if there was an answer for how to deal with this?

Not a maintainer, but since it's just a warning the simplest way to deal with it is to ignore it either globally^1 or in the pytest config^2 if you use that.

There seems to be an open PR to address this: https://github.com/sdispater/pendulum/pull/803.