Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.12: Deprecated utcnow and utcfromtimestamp #11908

Closed
pmisik opened this issue Aug 15, 2023 · 2 comments · Fixed by #11909
Closed

Python 3.12: Deprecated utcnow and utcfromtimestamp #11908

pmisik opened this issue Aug 15, 2023 · 2 comments · Fixed by #11909
Labels

Comments

@pmisik
Copy link

pmisik commented Aug 15, 2023

Describe the incorrect behavior you saw
datetime.datetime.utcnow and datetime.datetime.utcfromtimestamp raise deprecation warnings in Python 3.12.

Describe how to cause this behavior

While running trial on buildbot this generates lots of deprecation warnings like:

Traceback (most recent call last):
  File "C:\P\twisted\src\twisted\logger\_observer.py", line 81, in __call__
    observer(event)
  File "C:\P\twisted\src\twisted\logger\_legacy.py", line 90, in __call__
    self.legacyObserver(event)
  File "C:\P\twisted\src\twisted\python\log.py", line 544, in emit
    timeStr = self.formatTime(eventDict["time"])
  File "C:\P\twisted\src\twisted\python\log.py", line 514, in formatTime
    tzOffset = -self.getTimezoneOffset(when)
  File "C:\P\twisted\src\twisted\python\log.py", line 493, in getTimezoneOffset
    offset = datetime.utcfromtimestamp(when) - datetime.fromtimestamp(when)
builtins.DeprecationWarning: datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.fromtimestamp(timestamp, datetime.UTC).
E           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Running buildbot trial with current HEAD & current trunk of twisted.

Describe the correct behavior you'd like to see
No deprecation warning reported while running trial under python 3.12.

Testing environment

  • Operating System and Version; paste the output of these commands:
OS Name:                   Microsoft Windows 11 Home
OS Version:                10.0.22621 N/A Build 22621
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Workstation
OS Build Type:             Multiprocessor Free
System Manufacturer:       Microsoft Corporation
BIOS Version:              Microsoft Corporation 15.11.140, 8. 7. 2022
  • Twisted version
    22.10.0.post0
    a9ee8e5
  • Reactor [e.g. select, iocp]
    twisted-iocpsupport 1.0.4

Additional context

@adiroiban
Copy link
Member

Thanks for the report.

Happy to receive a PR with a fix for this :)

@adiroiban
Copy link
Member

@pmisik not that until just now, twisted/twisted was not working/supported on 3.12

You can now try to install Twisted over git and see if this is still an issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants