prkumar / uplink

A Declarative HTTP Client for Python
https://uplink.readthedocs.io/
MIT License
1.07k stars 61 forks source link

Fix deprecation warning that appear in Python 3.8+ #203

Closed muriloviana closed 2 years ago

muriloviana commented 4 years ago

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

Describe the solution you'd like Would be very welcome if we add support for Python 3.8.

Additional context I can work on it if necessary.

prkumar commented 4 years ago

Hi @muriloviana - Adding support for 3.8 sounds good to me. Although I haven't tried running uplink with Python 3.8, I believe the library should be in a good state to support. The only blocker I can think of is #201, but I believe that shouldn't be a problem since the deprecation of importing ABCs from collections has been delayed to 3.9, as per https://docs.python.org/3/whatsnew/3.8.html#api-and-feature-removals.

You are more than welcome to work on this if you have the bandwidth. Let me know if decide to take this one on. Thanks!

tirkarthi commented 4 years ago

collections related warning has been further delayed to Python 3.10

muriloviana commented 4 years ago

Cool, I'm going to work on that.

tirkarthi commented 3 years ago

The change has been merged in Python 3.10 : https://github.com/python/cpython/pull/23754

tirkarthi commented 3 years ago

I ran the project under 3.9 and I don't see any errors. There are several warnings that the project might break in Python 3.10. Also Python 3.8 has been added to travis in https://github.com/prkumar/uplink/pull/186/files so I guess python 3.8 is supported. collections related warnings have been fixed in https://github.com/prkumar/uplink/pull/201

tox -e py   
GLOB sdist-make: /root/checked_repos/uplink/setup.py
py create: /root/checked_repos/uplink/.tox/py
py installdeps: pipenv
py inst: /root/checked_repos/uplink/.tox/.tmp/package/1/uplink-0.9.4.zip
py installed: appdirs==1.4.4,certifi==2020.12.5,chardet==4.0.0,distlib==0.3.1,filelock==3.0.12,idna==2.10,pipenv==2020.11.15,requests==2.25.1,six==1.15.0,uplink @ file:///root/checked_repos/uplink/.tox/.tmp/package/1/uplink-0.9.4.zip,uritemplate==3.0.1,urllib3==1.26.3,virtualenv==20.4.2,virtualenv-clone==0.5.4
py run-test-pre: PYTHONHASHSEED='3979044358'
py run-test: commands[0] | pipenv install --skip-lock
Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS=1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY=-1 to suppress this warning.
Installing dependencies from Pipfile...
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 1/1 — 00:00:22
py run-test: commands[1] | pipenv run py.test tests --cov-config .coveragerc --cov=uplink
Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS=1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY=-1 to suppress this warning.
========================================================================= test session starts ==========================================================================
platform linux -- Python 3.9.0, pytest-4.6.5, py-1.10.0, pluggy-0.13.1
cachedir: .tox/py/.pytest_cache
rootdir: /root/checked_repos/uplink
plugins: twisted-1.13.2, cov-2.11.1, mock-3.2.0
collected 389 items                                                                                                                                                    

tests/integration/test_basic.py .....                                                                                                                            [  1%]
tests/integration/test_extend.py ..                                                                                                                              [  1%]
tests/integration/test_handlers.py .....                                                                                                                         [  3%]
tests/integration/test_ratelimit.py .....                                                                                                                        [  4%]
tests/integration/test_retry.py ........                                                                                                                         [  6%]
tests/integration/test_returns.py ....                                                                                                                           [  7%]
tests/unit/test__extras.py ..                                                                                                                                    [  7%]
tests/unit/test_arguments.py ...........................................................................................................                         [ 35%]
tests/unit/test_auth.py ..................                                                                                                                       [ 40%]
tests/unit/test_builder.py ...............                                                                                                                       [ 43%]
tests/unit/test_clients.py .............................                                                                                                         [ 51%]
tests/unit/test_commands.py .....................                                                                                                                [ 56%]
tests/unit/test_converters.py .............................................................                                                                      [ 72%]
tests/unit/test_decorators.py ............................                                                                                                       [ 79%]
tests/unit/test_helpers.py .......                                                                                                                               [ 81%]
tests/unit/test_hooks.py .......                                                                                                                                 [ 83%]
tests/unit/test_io.py ...........................                                                                                                                [ 90%]
tests/unit/test_models.py ....                                                                                                                                   [ 91%]
tests/unit/test_retry.py ...................                                                                                                                     [ 96%]
tests/unit/test_returns.py ....                                                                                                                                  [ 97%]
tests/unit/test_session.py ......                                                                                                                                [ 98%]
tests/unit/test_utils.py .....                                                                                                                                   [100%]

=========================================================================== warnings summary ===========================================================================
uplink/clients/io/asyncio_strategy.py:15
  /root/checked_repos/uplink/uplink/clients/io/asyncio_strategy.py:15: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def invoke(self, func, args, kwargs, callback):

uplink/clients/io/asyncio_strategy.py:26
  /root/checked_repos/uplink/uplink/clients/io/asyncio_strategy.py:26: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def sleep(self, duration, callback):

uplink/clients/io/asyncio_strategy.py:32
  /root/checked_repos/uplink/uplink/clients/io/asyncio_strategy.py:32: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def finish(self, response):

uplink/clients/io/asyncio_strategy.py:37
  /root/checked_repos/uplink/uplink/clients/io/asyncio_strategy.py:37: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def execute(self, executable):

uplink/clients/aiohttp_.py:83
  /root/checked_repos/uplink/uplink/clients/aiohttp_.py:83: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def session(self):

uplink/clients/aiohttp_.py:132
  /root/checked_repos/uplink/uplink/clients/aiohttp_.py:132: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def send(self, request):

uplink/returns.py:158
uplink/returns.py:158
  /root/checked_repos/uplink/uplink/returns.py:158: DeprecationWarning: The `member` argument of @returns.json is deprecated and will be removed in v1.0.0. Use `key` instead.
    warnings.warn(

tests/integration/test_retry.py::test_retry_with_asyncio
  /root/checked_repos/uplink/tests/integration/test_retry.py:131: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def coroutine():

tests/unit/test_builder.py::test_build_failure
tests/unit/test_builder.py::test_build
tests/unit/test_builder.py::test_inject
  /root/checked_repos/uplink/uplink/builder.py:377: DeprecationWarning: `uplink.build` is deprecated and will be removed in v1.0.0. To construct a consumer instance, have `Service` inherit `uplink.Consumer` then instantiate (e.g., `Service(...)`). 
    warnings.warn(

tests/unit/test_clients.py::TestAiohttp::test_request_send
  /root/checked_repos/uplink/tests/unit/test_clients.py:233: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def request(*args, **kwargs):

tests/unit/test_clients.py::TestAiohttp::test_callback
  /root/checked_repos/uplink/tests/unit/test_clients.py:255: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def request(*args, **kwargs):

tests/unit/test_clients.py::TestAiohttp::test_callback
  <string>:2: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead

tests/unit/test_clients.py::TestAiohttp::test_callback
  /root/checked_repos/uplink/uplink/clients/aiohttp_.py:93: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    callback = self._sync_callback_adapter(callback)

tests/unit/test_clients.py::TestAiohttp::test_wrap_callback
tests/unit/test_clients.py::TestAiohttp::test_threaded_callback
tests/unit/test_clients.py::TestAiohttp::test_threaded_callback
  /root/checked_repos/uplink/uplink/clients/aiohttp_.py:22: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    coroutine_callback = asyncio.coroutine(callback)

tests/unit/test_clients.py::TestAiohttp::test_wrap_callback
tests/unit/test_clients.py::TestAiohttp::test_threaded_callback
tests/unit/test_clients.py::TestAiohttp::test_threaded_callback
  /root/checked_repos/uplink/uplink/clients/aiohttp_.py:25: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def new_callback(response):

tests/unit/test_clients.py::TestAiohttp::test_wrap_callback
  /root/checked_repos/uplink/tests/unit/test_clients.py:302: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    coroutine_callback = asyncio.coroutine(callback)

tests/unit/test_clients.py::TestAiohttp::test_threaded_callback
  /root/checked_repos/uplink/tests/unit/test_clients.py:314: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    response.text = asyncio.coroutine(mocker.stub())

tests/unit/test_clients.py::TestAiohttp::test_threaded_coroutine
  /root/checked_repos/uplink/tests/unit/test_clients.py:350: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def coroutine():

tests/unit/test_clients.py::TestAiohttp::test_threaded_response
  /root/checked_repos/uplink/tests/unit/test_clients.py:367: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
    def coroutine():

-- Docs: https://docs.pytest.org/en/latest/warnings.html

----------- coverage: platform linux, python 3.9.0-final-0 -----------
Name                                     Stmts   Miss Branch BrPart  Cover   Missing
------------------------------------------------------------------------------------
uplink/__init__.py                          15      0      0      0   100%
uplink/_extras.py                           34      0     10      0   100%
uplink/arguments.py                        303      0     52      0   100%
uplink/auth.py                              61      0     14      0   100%
uplink/builder.py                          176      0     26      0   100%
uplink/clients/__init__.py                  13      0      2      0   100%
uplink/clients/aiohttp_.py                 101      0     20      0   100%
uplink/clients/exceptions.py                10      0      0      0   100%
uplink/clients/io/__init__.py                9      0      0      0   100%
uplink/clients/io/asyncio_strategy.py       27      0      0      0   100%
uplink/clients/io/blocking_strategy.py      19      0      0      0   100%
uplink/clients/io/execution.py             106      0      4      0   100%
uplink/clients/io/state.py                 132      0      0      0   100%
uplink/clients/io/templates.py              27      0      4      0   100%
uplink/clients/io/transitions.py            21      0      0      0   100%
uplink/clients/io/twisted_strategy.py       32      0      2      0   100%
uplink/clients/register.py                  23      0     10      0   100%
uplink/clients/requests_.py                 38      0      8      0   100%
uplink/clients/twisted_.py                  18      0      2      0   100%
uplink/commands.py                         163      0     20      0   100%
uplink/compat.py                             3      0      0      0   100%
uplink/converters/__init__.py               64      0      8      0   100%
uplink/converters/keys.py                   35      0      6      0   100%
uplink/converters/marshmallow_.py           49      0      8      0   100%
uplink/converters/pydantic_.py              53      0     18      0   100%
uplink/converters/register.py               17      0      2      0   100%
uplink/converters/standard.py               16      0      8      0   100%
uplink/converters/typing_.py                65      0     18      0   100%
uplink/decorators.py                       173      0     44      0   100%
uplink/exceptions.py                        12      0      0      0   100%
uplink/helpers.py                           68      0      4      0   100%
uplink/hooks.py                             42      0     14      0   100%
uplink/models.py                            61      0      2      0   100%
uplink/ratelimit.py                         71      0     10      0   100%
uplink/retry/__init__.py                     3      0      0      0   100%
uplink/retry/_helpers.py                     8      0      2      0   100%
uplink/retry/backoff.py                     18      0      2      0   100%
uplink/retry/retry.py                       60      0     26      0   100%
uplink/retry/stop.py                        41      0      2      0   100%
uplink/retry/when.py                        43      0      2      0   100%
uplink/returns.py                           88      0      8      0   100%
uplink/session.py                           38      0      6      0   100%
uplink/types.py                              5      0      0      0   100%
uplink/utils.py                             31      2      0      0    94%   63-64
------------------------------------------------------------------------------------
TOTAL                                     2392      2    364      0    99%

=============================================================== 389 passed, 26 warnings in 7.96 seconds ================================================================
Exception ignored in: <function RequestsClient.__del__ at 0x7f53e99c3e50>
Traceback (most recent call last):
  File "/root/checked_repos/uplink/uplink/clients/requests_.py", line 33, in __del__
  File "/root/checked_repos/uplink/.tox/py/lib/python3.9/site-packages/requests/sessions.py", line 747, in close
  File "/root/checked_repos/uplink/.tox/py/lib/python3.9/site-packages/requests/adapters.py", line 325, in close
  File "/root/checked_repos/uplink/.tox/py/lib/python3.9/site-packages/urllib3/poolmanager.py", line 222, in clear
  File "/root/checked_repos/uplink/.tox/py/lib/python3.9/site-packages/urllib3/_collections.py", line 95, in clear
TypeError: 'NoneType' object is not callable
_______________________________________________________________________________ summary ________________________________________________________________________________
  py: commands succeeded
  congratulations :)
kamil-zabierek commented 2 years ago

ping What with this issue? from march nothing. on pypi i can see: Python :: 3 Python :: 3.5 Python :: 3.6 Python :: 3.7 Python :: 3.8 Python :: 3.9 Python :: 3.10 that's far from the truth ...

prkumar commented 2 years ago

Hi @kamil-zabierek - official support for 3.8+ was introduced in the latest release, v0.9.5.

If you are encountering an issue with using the library with Python 3.8+, could you share some details?

kamil-zabierek commented 2 years ago

Hi @kamil-zabierek - this should be fixed in the latest release, v0.9.5.

If you are encountering an issue with using the library with Python 3.8+, could you share some details?

i just started project with uplink dependency (py3.9) and i can see deprecation warnings. I wonder if it's worth wading into it or removing this library

prkumar commented 2 years ago

Oh, I see... Those deprecation warnings should not cause issues for your usage of uplink with py3.9. The presence of deprecation warnings does not mean that the library doesn't support the current python version. It just indicates that the uplink version you are using will not support a future python version that removes the deprecated feature.

Hence, your original comment sort of confused me, since I interpreted it as suggesting that uplink was broken for py3.8+. Instead, it seems rather that you are put off by the warnings appearing in the console, which is totally understandable.

I can understand how these warnings can cause trepidation for newcomers that see them and want to run the other way. To that end, I believe your concerns will be addressed once we remove our usage of @couroutine. I think this is definitely a P1.

prkumar commented 2 years ago

I've submitted #248, which removes all "@asyncio.coroutine" usage in the library.

prkumar commented 2 years ago

I'm planning on releasing the change with v0.9.6 on Monday evening PST

prkumar commented 2 years ago

All asyncio.coroutine warnings should disappear after upgrading to v0.9.6, which is available in PyPI now.