From ecb58731c7209494cc7ebd87ff86f8f2b91e3717 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Tue, 19 Nov 2024 09:55:20 +0100 Subject: [PATCH 1/3] stop guarding typing imports, we're Python3-only now --- apypie/action.py | 9 +++------ apypie/api.py | 9 ++++----- apypie/foreman.py | 7 ++----- apypie/inflector.py | 5 +---- apypie/resource.py | 9 +++------ apypie/route.py | 5 +---- 6 files changed, 14 insertions(+), 30 deletions(-) diff --git a/apypie/action.py b/apypie/action.py index 9d3f27e..7d09c66 100644 --- a/apypie/action.py +++ b/apypie/action.py @@ -4,6 +4,8 @@ from __future__ import print_function, absolute_import +from typing import Optional, Any, Iterable, List, TYPE_CHECKING # pylint: disable=unused-import # noqa: F401 + from apypie.route import Route from apypie.example import Example from apypie.param import Param @@ -14,13 +16,8 @@ except NameError: # Python 3 has no basestring basestring = str # pylint: disable=invalid-name,redefined-builtin -try: - from typing import Optional, Any, Iterable, List, TYPE_CHECKING # pylint: disable=unused-import -except ImportError: - TYPE_CHECKING = False - if TYPE_CHECKING: - from apypie.api import Api # pylint: disable=cyclic-import,unused-import + from apypie.api import Api # pylint: disable=cyclic-import,unused-import # noqa: F401 class Action(object): diff --git a/apypie/api.py b/apypie/api.py index 8450271..ef2ca7f 100644 --- a/apypie/api.py +++ b/apypie/api.py @@ -21,11 +21,10 @@ from apypie.resource import Resource from apypie.exceptions import DocLoadingError -try: - from typing import Any, Iterable, Optional # pylint: disable=unused-import - from apypie.action import Action # pylint: disable=unused-import -except ImportError: - pass +from typing import Any, Iterable, Optional, TYPE_CHECKING # pylint: disable=unused-import # noqa: F401 + +if TYPE_CHECKING: + from apypie.action import Action # pylint: disable=unused-import # noqa: F401 NO_CONTENT = 204 diff --git a/apypie/foreman.py b/apypie/foreman.py index 276a558..4e0d388 100644 --- a/apypie/foreman.py +++ b/apypie/foreman.py @@ -5,14 +5,11 @@ """ import time -try: - from typing import cast, Optional, Set, Tuple -except ImportError: - pass +from typing import cast, Optional, Set, Tuple from apypie.api import Api -from apypie.resource import Resource # pylint: disable=unused-import +from apypie.resource import Resource # pylint: disable=unused-import # noqa: F401 # Foreman supports "per_page=all" since 2.2 (https://projects.theforeman.org/issues/29909) # But plugins, especially Katello, do not: https://github.com/Katello/katello/pull/11126 diff --git a/apypie/inflector.py b/apypie/inflector.py index 428e373..529f956 100644 --- a/apypie/inflector.py +++ b/apypie/inflector.py @@ -7,10 +7,7 @@ import re -try: - from typing import Iterable, Tuple # pylint: disable=unused-import -except ImportError: - pass +from typing import Iterable, Tuple # pylint: disable=unused-import # noqa: F401 class Inflections(object): diff --git a/apypie/resource.py b/apypie/resource.py index 8afd702..91fab00 100644 --- a/apypie/resource.py +++ b/apypie/resource.py @@ -4,15 +4,12 @@ from __future__ import print_function, absolute_import -from apypie.action import Action +from typing import Optional, Any, List, TYPE_CHECKING # pylint: disable=unused-import # noqa: F401 -try: - from typing import Optional, Any, List, TYPE_CHECKING # pylint: disable=unused-import -except ImportError: - TYPE_CHECKING = False +from apypie.action import Action if TYPE_CHECKING: - from apypie.api import Api # pylint: disable=cyclic-import,unused-import + from apypie.api import Api # pylint: disable=cyclic-import,unused-import # noqa: F401 class Resource(object): diff --git a/apypie/route.py b/apypie/route.py index 6fe5bf3..3fb1ac8 100644 --- a/apypie/route.py +++ b/apypie/route.py @@ -9,10 +9,7 @@ except ImportError: from urllib import quote # type: ignore -try: - from typing import List, Optional # pylint: disable=unused-import -except ImportError: - pass +from typing import List, Optional # pylint: disable=unused-import # noqa: F401 class Route(object): From 09d1b81a7e9d9344b1977c9b6dc7db47cee8c988 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Tue, 19 Nov 2024 09:56:25 +0100 Subject: [PATCH 2/3] always use urllib.parse, Python2 is no more --- apypie/api.py | 5 +---- apypie/route.py | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/apypie/api.py b/apypie/api.py index ef2ca7f..c6f7978 100644 --- a/apypie/api.py +++ b/apypie/api.py @@ -12,10 +12,7 @@ except ImportError: JSONDecodeError = ValueError # type: ignore import os -try: - from urlparse import urljoin # type: ignore -except ImportError: - from urllib.parse import urljoin # type: ignore +from urllib.parse import urljoin # type: ignore import requests from apypie.resource import Resource diff --git a/apypie/route.py b/apypie/route.py index 3fb1ac8..a2bff7d 100644 --- a/apypie/route.py +++ b/apypie/route.py @@ -4,10 +4,7 @@ from __future__ import print_function, absolute_import -try: - from urllib.parse import quote # type: ignore -except ImportError: - from urllib import quote # type: ignore +from urllib.parse import quote # type: ignore from typing import List, Optional # pylint: disable=unused-import # noqa: F401 From b535d9e34cd4774cf0a18b244b946ffacdd20820 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Tue, 19 Nov 2024 09:57:10 +0100 Subject: [PATCH 3/3] always use json.decoder, Python2 is no more --- apypie/api.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/apypie/api.py b/apypie/api.py index c6f7978..98c6bf4 100644 --- a/apypie/api.py +++ b/apypie/api.py @@ -7,10 +7,7 @@ import errno import glob import json -try: - from json.decoder import JSONDecodeError # type: ignore -except ImportError: - JSONDecodeError = ValueError # type: ignore +from json.decoder import JSONDecodeError # type: ignore import os from urllib.parse import urljoin # type: ignore import requests