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

Support python 3.11 and aiohttp 3.8 #224

Conversation

marcinsulikowski
Copy link
Contributor

@marcinsulikowski marcinsulikowski commented Oct 19, 2022

Remove remnants of aiohttp 2.x and Python 3.5 support

Commit adfb650 removed support for aiohttp 2.x and Python
3.5 but there are still some remnants of these left. We get rid of them.
This also removes one mypy warning:

compat.py:31: error: All conditional function variants must have identical signatures [misc]

Add type annotation for stream_reader_factory

Remove aiohttp 2.x from tox.ini

We no longer run tests against aiohttp 2.x so we don't need it in
tox.ini.

Add Python 3.10 support

aioresponses works with Python 3.10 with no issues so we update the
package metadata to say that, and we update the list of test
environments to include Python 3.10.

Add tests against aiohttp 3.8

aioresponses works with aiohttp 3.8 so we extend the list of test
environments to include this version.

Add Python 3.10 tests to GitHub workflows

Add tests against aiohttp 3.8 to GitHub workflows

Drop Python 3.6 support

We cannot run tests with Python 3.10 using Pytest 6.x due to [1]. This
is fixed in Pytest 7.x but Pytest 7.x no longer supports Python 3.6
which aioresponses tries to support. However because Python 3.6 is
already past the EOL date, the simplest solution is to no longer test
with Python 3.6 and to stop declaring support for that version.

[1] pytest-dev/pytest#8546

Update Pytest to the latest version to fix tests on Python 3.10

Our tests are filing on Python 3.10 due to [1] so we update Pytest in
requirements-dev.txt to the latest version.

[1] pytest-dev/pytest#8546

Don't test with aiohttp 3.6 and older on Python 3.10

aiohttp 3.6 and older use Python features which were removed in Python
3.10:

            assert port is not None
>           hosts = await asyncio.shield(self._resolve_host(
                host,
                port,
                traces=traces), loop=self._loop)
E               TypeError: shield() got an unexpected keyword argument 'loop'

.tox/py3.10-aiohttp35/lib/python3.10/site-packages/aiohttp/connector.py:952: TypeError

To avoid test failures, we remove unsupported combinations from GitHub
workflows.

Drop support for aiohttp 3.2.x and older

aiohttp 3.2.x and older don't work on Python 3.7 and because we now
require Python 3.7+, we can drop support for aiohttp 3.0, 3.1, and 3.2.

Merge remote-tracking branch 'pnuckowski/aioresponses/master' into support-python-3.10-and-aiohttp-3.8

Add Python 3.11 support

aioresponses works with Python 3.11 with no issues so we update the
package metadata to say that, and we update the list of test
environments to include Python 3.11. Python 3.11 is supported by aiohttp
starting from its v3.8 ([1]), and we also need newer yarl ([2]).

[1] aio-libs/aiohttp#6600
[2] aio-libs/yarl#706

Commit adfb650 removed support for aiohttp 2.x and Python
3.5 but there are still some remnants of these left. We get rid of them.
This also removes one `mypy` warning:

> compat.py:31: error: All conditional function variants must have identical signatures [misc]
We no longer run tests against aiohttp 2.x so we don't need it in
`tox.ini`.
@marcinsulikowski
Copy link
Contributor Author

A couple places in README files should also be updated but this is covered by #223

@marcinsulikowski marcinsulikowski force-pushed the support-python-3.10-and-aiohttp-3.8 branch 2 times, most recently from 2ce038c to afd9bf9 Compare October 19, 2022 21:32
@marcinsulikowski
Copy link
Contributor Author

I needed a few attempts but it seems that all test combinations are finally passing.

aioresponses works with Python 3.10 with no issues so we update the
package metadata to say that, and we update the list of test
environments to include Python 3.10.
aioresponses works with aiohttp 3.8 so we extend the list of test
environments to include this version.
@marcinsulikowski
Copy link
Contributor Author

But the coverage report tells that there's some dead code. Let me fix that as well.

We cannot run tests with Python 3.10 using Pytest 6.x due to [1]. This
is fixed in Pytest 7.x but Pytest 7.x no longer supports Python 3.6
which aioresponses tries to support. However because Python 3.6 is
already past the EOL date, the simplest solution is to no longer test
with Python 3.6 and to stop declaring support for that version.

[1] pytest-dev/pytest#8546
Our tests are filing on Python 3.10 due to [1] so we update Pytest in
`requirements-dev.txt` to the latest version.

[1] pytest-dev/pytest#8546
aiohttp 3.6 and older use Python features which were removed in Python
3.10:

                assert port is not None
    >           hosts = await asyncio.shield(self._resolve_host(
                    host,
                    port,
                    traces=traces), loop=self._loop)
    E               TypeError: shield() got an unexpected keyword argument 'loop'

    .tox/py3.10-aiohttp35/lib/python3.10/site-packages/aiohttp/connector.py:952: TypeError

To avoid test failures, we remove unsupported combinations from GitHub
workflows.
aiohttp 3.2.x and older don't work on Python 3.7 and because we now
require Python 3.7+, we can drop support for aiohttp 3.0, 3.1, and 3.2.
@codecov-commenter
Copy link

codecov-commenter commented Oct 19, 2022

Codecov Report

Base: 96.50% // Head: 96.68% // Increases project coverage by +0.18% 🎉

Coverage data is based on head (0f723fe) compared to base (f330e71).
Patch coverage: 100.00% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #224      +/-   ##
==========================================
+ Coverage   96.50%   96.68%   +0.18%     
==========================================
  Files           3        3              
  Lines         343      332      -11     
==========================================
- Hits          331      321      -10     
+ Misses         12       11       -1     
Impacted Files Coverage Δ
aioresponses/compat.py 75.67% <100.00%> (+0.67%) ⬆️
aioresponses/core.py 99.31% <100.00%> (-0.02%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@pnuckowski
Copy link
Owner

pnuckowski commented Dec 14, 2022

Wow, a lot of work was done :)
Yes, lets drop py36

@gaby
Copy link
Contributor

gaby commented Dec 14, 2022

Looking forward to seeing this get merged! 🎉

@marcinsulikowski
Copy link
Contributor Author

Things changed a but since I created this PR. I will add conflict resolution and support for 3.11.

aioresponses works with Python 3.11 with no issues so we update the
package metadata to say that, and we update the list of test
environments to include Python 3.11. Python 3.11 is supported by aiohttp
starting from its v3.8 ([1]), and we also need newer `yarl` ([2]).

[1] aio-libs/aiohttp#6600
[2] aio-libs/yarl#706
@marcinsulikowski marcinsulikowski changed the title Support python 3.10 and aiohttp 3.8 Support python 3.11 and aiohttp 3.8 Feb 18, 2023
@gaby
Copy link
Contributor

gaby commented Feb 18, 2023

@pnuckowski This PR is ready now

@avalanchy
Copy link

@pnuckowski bump!

@@ -5,6 +5,7 @@
from urllib.parse import parse_qsl, urlencode

from aiohttp import __version__ as aiohttp_version, StreamReader
from aiohttp.client_proto import ResponseHandler
from multidict import MultiDict
from pkg_resources import parse_version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package throws the following warning when running locally

DeprecationWarning: pkg_resources is deprecated as an API

The official documentation suggests the use of importlib.resources, importlib.metadata as a replacement. More info here: https://setuptools.pypa.io/en/stable/pkg_resources.html

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All that's being used here is parse_version with literal version strings. I'd suggest packaging.version.parse instead of anything from importlib.

@pnuckowski Is anything else blocking this from being merged and released? I got bit by this today and the PR has been sitting for a long time now.

Failing that, does anyone know of a fork that includes Python 3.11 support?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brettdh I'm wondering the same thing :-S

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm that all unit tests pass in Python 3.11.4 after changing this line (and one other like it, in tests/test_aioresponses.py) to this:

from packaging.version import parse as parse_version

Using a private fork for now, but hoping that can get fixed, merged, and released soon.

@pnuckowski pnuckowski merged commit 56b8433 into pnuckowski:master Jun 19, 2023
@gaby
Copy link
Contributor

gaby commented Jun 19, 2023

@pnuckowski Thank you! 💪

@brettdh
Copy link

brettdh commented Jun 20, 2023

I was very confused about:

  1. why this was merged without the pkg_resources fix above; and
  2. why tests are passing on 3.11 even without that fix; and
  3. why import aioresponses still failed in my project's 3.11 virtualenv; AND
  4. why import pkg_resources failed in my project's 3.11 virtualenv but succeeded in my aioresponses 3.11 virtualenv

and then I realised that my aioresponses virtualenv also includes setuptools, and my other project's virtualenv does not (for some reason, perhaps owing to me having created the former with python -m venv and the other with pyenv virtualenv create). 😑 Mystery (mostly) solved.

@pnuckowski Thanks for the quick response and for merging! Looking forward to a new release.

@brettdh
Copy link

brettdh commented Jun 20, 2023

Er, whoops; celebrated too soon. The pkg_resources issue above means that aioresponses still fails with this error in my project's unit tests (under pytest):

ImportError while importing test module '/Users/brhiggins/src/myproj/tests/test_foo.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../../../.pyenv/versions/3.11.4/lib/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_foo.py:6: in <module>
    from aioresponses import aioresponses
../../../../.pyenv/versions/3.11.4/envs/myproj/lib/python3.11/site-packages/aioresponses/__init__.py:2: in <module>
    from .core import CallbackResult, aioresponses
../../../../.pyenv/versions/3.11.4/envs/myproj/lib/python3.11/site-packages/aioresponses/core.py:33: in <module>
    from .compat import (
../../../../.pyenv/versions/3.11.4/envs/myproj/lib/python3.11/site-packages/aioresponses/compat.py:10: in <module>
    from pkg_resources import parse_version
E   ModuleNotFoundError: No module named 'pkg_resources'

This is with aioresponses installed from 56b843319d5d0ae8a405f188e68d7ba8c7573bc8.

@iamibi
Copy link
Contributor

iamibi commented Jun 20, 2023

Er, whoops; celebrated too soon. The pkg_resources issue above means that aioresponses still fails with this error in my project's unit tests (under pytest):

ImportError while importing test module '/Users/brhiggins/src/myproj/tests/test_foo.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../../../.pyenv/versions/3.11.4/lib/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_foo.py:6: in <module>
    from aioresponses import aioresponses
../../../../.pyenv/versions/3.11.4/envs/myproj/lib/python3.11/site-packages/aioresponses/__init__.py:2: in <module>
    from .core import CallbackResult, aioresponses
../../../../.pyenv/versions/3.11.4/envs/myproj/lib/python3.11/site-packages/aioresponses/core.py:33: in <module>
    from .compat import (
../../../../.pyenv/versions/3.11.4/envs/myproj/lib/python3.11/site-packages/aioresponses/compat.py:10: in <module>
    from pkg_resources import parse_version
E   ModuleNotFoundError: No module named 'pkg_resources'

This is with aioresponses installed from 56b843319d5d0ae8a405f188e68d7ba8c7573bc8.

The workaround is to install the setuptools when running test cases. Specially in case of CI builds. Any latest version of setuptools should work.

@brettdh
Copy link

brettdh commented Jun 20, 2023

@iamibi Thanks; that works for now.

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

Successfully merging this pull request may close these issues.

None yet

7 participants