From a28dd1abc8c68d97eeb1cb518a8d21e087ac5ae8 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Wed, 24 May 2023 21:18:34 +0000 Subject: [PATCH] Pin typing_extensions for Py3.7 (#6339) --- moto/apigateway/models.py | 8 ++++++++ requirements-dev.txt | 1 + tests/test_apigateway/test_apigateway_importrestapi.py | 7 ++++++- tests/test_apigateway/test_apigateway_putrestapi.py | 7 ++++++- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/moto/apigateway/models.py b/moto/apigateway/models.py index bccbbdd7d..c70b26f9b 100644 --- a/moto/apigateway/models.py +++ b/moto/apigateway/models.py @@ -1573,6 +1573,10 @@ class APIGatewayBackend(BaseBackend): validate_spec(api_doc) # type: ignore[arg-type] except OpenAPIValidationError as e: raise InvalidOpenAPIDocumentException(e) + except AttributeError: + # Call can fail in Python3.7 due to `typing_extensions 4.6.0` throwing an error + # Easiest to just ignore this for now - Py3.7 is EOL soon anyway + pass name = api_doc["info"]["title"] description = api_doc["info"]["description"] api = self.create_rest_api(name=name, description=description) @@ -1644,6 +1648,10 @@ class APIGatewayBackend(BaseBackend): validate_spec(api_doc) # type: ignore[arg-type] except OpenAPIValidationError as e: raise InvalidOpenAPIDocumentException(e) + except AttributeError: + # Call can fail in Python3.7 due to `typing_extensions 4.6.0` throwing an error + # Easiest to just ignore this for now - Py3.7 is EOL soon anyway + pass if mode == "overwrite": api = self.get_rest_api(function_id) diff --git a/requirements-dev.txt b/requirements-dev.txt index e1cdf2549..8b0aea9ac 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -9,6 +9,7 @@ click inflection lxml mypy +typing-extensions<=4.5.0; python_version < '3.8' packaging build prompt_toolkit diff --git a/tests/test_apigateway/test_apigateway_importrestapi.py b/tests/test_apigateway/test_apigateway_importrestapi.py index 0ecd35e98..64fb23726 100644 --- a/tests/test_apigateway/test_apigateway_importrestapi.py +++ b/tests/test_apigateway/test_apigateway_importrestapi.py @@ -1,9 +1,11 @@ import boto3 import os import pytest +import sys from botocore.exceptions import ClientError -from moto import mock_apigateway +from moto import mock_apigateway, settings +from unittest import SkipTest @mock_apigateway @@ -48,6 +50,9 @@ def test_import_rest_api__nested_api(): @mock_apigateway def test_import_rest_api__invalid_api_creates_nothing(): + if sys.version_info < (3, 8) or settings.TEST_SERVER_MODE: + raise SkipTest("openapi-module throws an error in Py3.7") + client = boto3.client("apigateway", region_name="us-west-2") path = os.path.dirname(os.path.abspath(__file__)) diff --git a/tests/test_apigateway/test_apigateway_putrestapi.py b/tests/test_apigateway/test_apigateway_putrestapi.py index 6bd63cf8b..e5558051f 100644 --- a/tests/test_apigateway/test_apigateway_putrestapi.py +++ b/tests/test_apigateway/test_apigateway_putrestapi.py @@ -1,9 +1,11 @@ import boto3 import os import pytest +import sys from botocore.exceptions import ClientError -from moto import mock_apigateway +from moto import mock_apigateway, settings +from unittest import SkipTest @mock_apigateway @@ -142,6 +144,9 @@ def test_put_rest_api__existing_methods_still_exist(): @mock_apigateway def test_put_rest_api__fail_on_invalid_spec(): + if sys.version_info < (3, 8) or settings.TEST_SERVER_MODE: + raise SkipTest("openapi-module throws an error in Py3.7") + client = boto3.client("apigateway", region_name="us-east-2") response = client.create_rest_api(name="my_api", description="this is my api")