From a66052946c47b9895e2e2de8aa63e56d102d59c4 Mon Sep 17 00:00:00 2001 From: Alexander Shadchin Date: Sat, 1 Jan 2022 02:22:34 +0300 Subject: [PATCH] Fix uplink with Python 2.7 (#223) * Fix uplink with Python 2.7 * Switch on six.moves.collections_abc * Add abc in __all__ * Add link to GitHub Discussions for repo in README * Update "Question" GitHub issue template * Fix @uplink.*Map to not throw error if converter is None Fixes #221 * Fix B018 flake error Flake is failing with "B018 Found useless expression." https://app.travis-ci.com/github/prkumar/uplink/jobs/553555288 * Add 3.9 and 3.10.1 to travis build (#239) * Add 3.9 and 3.10 to travis build * Replace 3.10 with 3.10-dev * Update travis to use Ubuntu 18.04 18.04 has 3.10.0 and 3.10.1 according to: https://docs.travis-ci.com/user/languages/python/ * Bump python 3.10 to 3.10.1 in travis * Unpin pytest version Travis build for 3.10.1 failed because of issue in pytest that was fixed in a later release: https://github.com/pytest-dev/pytest/pull/8540 * Fix uplink with Python 2.7 * Switch on six.moves.collections_abc * Add abc in __all__ * Add python 2.7 to travis build * Omit "keywords" attribute when invoking setup for py2.7 Context: https://github.com/pypa/pipenv/issues/4357#issuecomment-685446578 * Pin pipenv==2018.11.26 for py2.7 travis build Context: https://github.com/pypa/pipenv/issues/4357#issuecomment-663311263 * Fix syntax error in travis config file * Try pinning pipenv version in tox.ini * Make integration tests work with py2.7 * Make integration tests work with py2.7 * Fix flake8 E231 error Co-authored-by: P. Raj Kumar Co-authored-by: Alexander Shadchinr --- .pre-commit-config.yaml | 10 +++++----- .travis.yml | 1 + AUTHORS.rst | 1 + tests/integration/test_form_url_encoded.py | 4 ++-- tests/integration/test_multipart.py | 4 ++-- tox.ini | 4 +++- uplink/arguments.py | 2 +- uplink/auth.py | 4 +--- uplink/clients/io/interfaces.py | 5 +---- uplink/commands.py | 2 +- uplink/compat.py | 3 ++- uplink/converters/__init__.py | 4 +--- uplink/converters/typing_.py | 2 +- uplink/decorators.py | 2 +- 14 files changed, 23 insertions(+), 25 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 74955b82..4ab905d7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,14 +1,14 @@ repos: - repo: https://github.com/ambv/black - rev: 18.6b4 + rev: 21.12b0 hooks: - id: black - python-version: python3.6 + python-version: python3.8 files: ^((uplink|examples|tests)\/.+|setup|docs\/conf)\.py$ -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v1.3.0 +- repo: https://github.com/pycqa/flake8 + rev: '4.0.1' hooks: - id: flake8 name: flake8 - python-version: python3.6 + python-version: python3.8 files: ^((uplink|examples|tests)\/.+|setup|docs\/conf)\.py$ diff --git a/.travis.yml b/.travis.yml index b01be3cf..1a6d1f62 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: python dist: bionic # Ubuntu 18.04 python: + - '2.7' - '3.5' - '3.6' - '3.7' diff --git a/AUTHORS.rst b/AUTHORS.rst index de74a9f5..2a403eb5 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -16,3 +16,4 @@ Contributors - Sakorn Waungwiwatsin (`@SakornW `_) - Jacob Floyd (`@cognifloyd `_) - Guilherme Crocetti (`@gmcrocetti `_) +- Alexander Shadchin (`@shadchin `_) diff --git a/tests/integration/test_form_url_encoded.py b/tests/integration/test_form_url_encoded.py index ad70befe..073ef41e 100644 --- a/tests/integration/test_form_url_encoded.py +++ b/tests/integration/test_form_url_encoded.py @@ -8,8 +8,8 @@ def test_without_converter(mock_response, mock_client): class Calendar(Consumer): @form_url_encoded - @put("/user/repos") - def add_event(self, **event_data: FieldMap): + @put("/user/repos", args={"event_data": FieldMap}) + def add_event(self, **event_data): pass mock_client.with_response(mock_response) diff --git a/tests/integration/test_multipart.py b/tests/integration/test_multipart.py index 7ab7e1f1..3c208c72 100644 --- a/tests/integration/test_multipart.py +++ b/tests/integration/test_multipart.py @@ -8,8 +8,8 @@ def test_without_converter(mock_response, mock_client): class Calendar(Consumer): @multipart - @post("/attachments") - def upload_attachments(self, **files: PartMap): + @post("/attachments", args={"files": PartMap}) + def upload_attachments(self, **files): pass mock_client.with_response(mock_response) diff --git a/tox.ini b/tox.ini index 19b1c350..d19f6cba 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,9 @@ # Website (June 2016): http://tox.readthedocs.io/en/latest/ [testenv] -deps = pipenv +deps = + pipenv == 2018.11.26 ; python_version == '2.7' + pipenv ; python_version > '2.7' commands = pipenv install --skip-lock pipenv run py.test tests \ --cov-config .coveragerc \ diff --git a/uplink/arguments.py b/uplink/arguments.py index 9503c1c3..82375656 100644 --- a/uplink/arguments.py +++ b/uplink/arguments.py @@ -4,12 +4,12 @@ """ # Standard library imports import collections -from collections import abc import functools import inspect # Local imports from uplink import exceptions, hooks, interfaces, utils +from uplink.compat import abc from uplink.converters import keys __all__ = [ diff --git a/uplink/auth.py b/uplink/auth.py index 3334b72d..9ba53f29 100644 --- a/uplink/auth.py +++ b/uplink/auth.py @@ -1,13 +1,11 @@ """This module implements the auth layer.""" -# Standard library imports -from collections import abc - # Third-party imports from requests import auth # Local imports from uplink import utils +from uplink.compat import abc __all__ = [ "ApiTokenParam", diff --git a/uplink/clients/io/interfaces.py b/uplink/clients/io/interfaces.py index ff810824..d0e4d31b 100644 --- a/uplink/clients/io/interfaces.py +++ b/uplink/clients/io/interfaces.py @@ -1,6 +1,3 @@ -# Standard library imports -from collections import abc - # Local imports from uplink import compat @@ -69,7 +66,7 @@ def on_failure(self, exc_type, exc_val, exc_tb): raise NotImplementedError -class Executable(abc.Iterator): +class Executable(compat.abc.Iterator): """An abstraction for iterating over the execution of a request.""" def __next__(self): diff --git a/uplink/commands.py b/uplink/commands.py index 6805412d..40200391 100644 --- a/uplink/commands.py +++ b/uplink/commands.py @@ -1,5 +1,4 @@ # Standard library imports -from collections import abc import functools # Local imports @@ -12,6 +11,7 @@ returns, utils, ) +from uplink.compat import abc __all__ = ["get", "head", "put", "post", "patch", "delete"] diff --git a/uplink/compat.py b/uplink/compat.py index d0ac368b..6b6ac98d 100644 --- a/uplink/compat.py +++ b/uplink/compat.py @@ -1,6 +1,7 @@ # Third-party imports import six -__all__ = ["reraise"] +__all__ = ["abc", "reraise"] +abc = six.moves.collections_abc reraise = six.reraise diff --git a/uplink/converters/__init__.py b/uplink/converters/__init__.py index fdc2fcf5..ebc73b1c 100644 --- a/uplink/converters/__init__.py +++ b/uplink/converters/__init__.py @@ -1,8 +1,6 @@ -# Standard library imports -from collections import abc - # Local imports from uplink._extras import installer, plugin +from uplink.compat import abc from uplink.converters import keys from uplink.converters.interfaces import Factory, ConverterFactory, Converter from uplink.converters.register import ( diff --git a/uplink/converters/typing_.py b/uplink/converters/typing_.py index 1c42ffd5..9f5f8f98 100644 --- a/uplink/converters/typing_.py +++ b/uplink/converters/typing_.py @@ -1,9 +1,9 @@ # Standard library imports import collections -from collections import abc import functools # Local imports +from uplink.compat import abc from uplink.converters import interfaces, register_default_converter_factory __all__ = ["TypingConverter", "ListConverter", "DictConverter"] diff --git a/uplink/decorators.py b/uplink/decorators.py index d0bfe6c0..bd32cf04 100644 --- a/uplink/decorators.py +++ b/uplink/decorators.py @@ -3,12 +3,12 @@ handling classes. """ # Standard library imports -from collections import abc import functools import inspect # Local imports from uplink import arguments, helpers, hooks, interfaces, utils +from uplink.compat import abc __all__ = [ "headers",