flask-restx icon indicating copy to clipboard operation
flask-restx copied to clipboard

Remove unnecessary dependency pytz

Open ErikBjare opened this issue 5 years ago • 4 comments

Is your feature request related to a problem? Please describe.

pytz is a somewhat complex dependency in some ways (it dumps hundreds of tzinfo files on the filesystem), yet it looks like it's not really needed since it's only used to set the UTC timezone for some timezone-aware datetimes.

See this search for usages: https://github.com/python-restx/flask-restx/search?q=pytz

Describe the solution you'd like

Removal of pytz as a dependency, and replace all references to pytz.UTC with datetime.timezone.utc.

Additional context

Since datetime.timezone is not available in Python 2.7, we might need to construct a tzinfo object by hand (should be trivial though, since it's just UTC). However, since there's https://github.com/python-restx/flask-restx/pull/113 I assume keeping Python 2.7 support might not be of interest anymore.

I volunteer to contribute a PR making this change, if there's interest.

ErikBjare avatar Dec 28 '20 13:12 ErikBjare

flask-restx imports pytz, and pytz seems to be deprecated, so the import fails. Removing it is a very good idea. I can't try out flask-restx unless it loads, so I don't even know if I want to use it yet.

File "c:\tools\miniconda3\envs\flask\lib\site-packages\flask_restx\inputs.py", line 29, in import pytz ModuleNotFoundError: No module named 'pytz'

brian32768 avatar Nov 29 '22 00:11 brian32768

Been a while since I created this issue.

Is this of interest to maintainers? My offer to make a PR still stands.

ErikBjare avatar Nov 29 '22 09:11 ErikBjare

Dear maintainers,

I did a fork of the project and fixed it this morning, it's so easy even I could do it. Removing an unneeded dependency seems like a good idea to me.

Please give Erik the go-ahead on this. It affects these 4 files.

    modified:   examples/zoo_app/requirements.txt
    modified:   flask_restx/inputs.py
    modified:   requirements/install.pip
    modified:   tests/test_inputs.py

brian32768 avatar Nov 29 '22 19:11 brian32768

pytz is now embedded in last python versions: Projects using Python 3.9 or later should be using the support now included as part of the standard library

What could be done: flask-restx could add the dependency to pytz only for python version older than 3.9.

gri38 avatar Oct 26 '23 09:10 gri38