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

DeprecationWarning for datetime.utcfromtimestamp() in Python 3.12 #71

Open
musicinmybrain opened this issue Jun 28, 2023 · 2 comments
Open

Comments

@musicinmybrain
Copy link

python3.12 -m venv _e
. _e/bin/activate
pip install -e .[pydantic]
pip install -r requirements/tests.in
python -m pytest
==================================== ERRORS ====================================
___________________ ERROR collecting tests/test_datetime.py ____________________
_e/lib64/python3.12/site-packages/_pytest/runner.py:341: in from_call
    result: Optional[TResult] = func()
_e/lib64/python3.12/site-packages/_pytest/runner.py:372: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
_e/lib64/python3.12/site-packages/_pytest/python.py:531: in collect
    self._inject_setup_module_fixture()
_e/lib64/python3.12/site-packages/_pytest/python.py:545: in _inject_setup_module_fixture
    self.obj, ("setUpModule", "setup_module")
_e/lib64/python3.12/site-packages/_pytest/python.py:310: in obj
    self._obj = obj = self._getobj()
_e/lib64/python3.12/site-packages/_pytest/python.py:528: in _getobj
    return self._importtestmodule()
_e/lib64/python3.12/site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
_e/lib64/python3.12/site-packages/_pytest/pathlib.py:565: in import_path
    importlib.import_module(module_name)
/usr/lib64/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1293: in _gcd_import
    ???
<frozen importlib._bootstrap>:1266: in _find_and_load
    ???
<frozen importlib._bootstrap>:1237: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:841: in _load_unlocked
    ???
_e/lib64/python3.12/site-packages/_pytest/assertion/rewrite.py:178: in exec_module
    exec(co, module.__dict__)
tests/test_datetime.py:5: in <module>
    import pytz
_e/lib64/python3.12/site-packages/pytz/__init__.py:20: in <module>
    from pytz.tzinfo import unpickler, BaseTzInfo
_e/lib64/python3.12/site-packages/pytz/tzinfo.py:27: in <module>
    _epoch = datetime.utcfromtimestamp(0)
E   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).

This will probably be fixed in pytz at some point; the issue is stub42/pytz#105.

In the longer term, it may be desirable to migrate away from pytz, as summarized in the introductory paragraph of the description for https://pypi.org/project/pytz-deprecation-shim/.

@samuelcolvin
Copy link
Owner

Yes, in the long term we should migrate away.

@MeggyCal
Copy link
Contributor

Just heads-up: the issue is fixed in pytz 2023.3.post1.

samuelcolvin added a commit that referenced this issue Nov 14, 2023
This is not the same as
#71, but it
originates at the same point. When I updated pytz to 2023.3.post1, I
started getting:
```
E       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).
```
This fixes it.

---------

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants