From 0684cbf6b7573bff9dd54955cf607526f00ca055 Mon Sep 17 00:00:00 2001 From: Ben Kehoe Date: Wed, 19 Jan 2022 17:11:32 -0700 Subject: [PATCH] v2.5: fix type annotations --- .github/workflows/pypi.yaml | 2 ++ CHANGELOG.md | 5 +++++ aws_error_utils/aws_error_utils.py | 10 +++++----- pyproject.toml | 4 +++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pypi.yaml b/.github/workflows/pypi.yaml index e0b4bee..70faa16 100644 --- a/.github/workflows/pypi.yaml +++ b/.github/workflows/pypi.yaml @@ -19,6 +19,8 @@ jobs: shell: bash - run: poetry run pytest shell: bash + - run: poetry run mypy aws_error_utils --ignore-missing-imports + shell: bash build-and-publish: needs: test runs-on: ubuntu-latest diff --git a/CHANGELOG.md b/CHANGELOG.md index f660de7..f21daf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +`aws-error-utils` uses [monotonic versioning](blog.appliedcompscilab.com/monotonic_versioning_manifesto/). + +## v2.5 +* Fix type annotations. + ## v2.4 * Require Python 3.6 as 3.5 is EOL. * Update `AWSErrorInfo` to be a dataclass. diff --git a/aws_error_utils/aws_error_utils.py b/aws_error_utils/aws_error_utils.py index bb81b0c..2ca1277 100644 --- a/aws_error_utils/aws_error_utils.py +++ b/aws_error_utils/aws_error_utils.py @@ -20,7 +20,7 @@ operation_name = e.operation_name """ -__version__ = "2.4.0" # update here and pyproject.toml +__version__ = "2.5.0" # update here and pyproject.toml __all__ = [ "AWSErrorInfo", @@ -37,7 +37,7 @@ import dataclasses import sys -from typing import Optional, List, Union, Callable +from typing import Optional, List, Union, Callable, Type from botocore.exceptions import BotoCoreError, ClientError @@ -130,7 +130,7 @@ def catch_aws_error( *args: Union[str, Callable], code: Union[None, str, List[str]] = None, operation_name: Union[None, str, List[str]] = None -) -> Exception: +) -> Type[BaseException]: """For use in an except statement, returns the current error's type if it matches the arguments, otherwise a non-matching error type Any positional arguments and the contents of the 'code' kwarg are matched @@ -163,7 +163,7 @@ def catch_aws_error( if args[0](client_error): matched = True elif aws_error_matches( - client_error, *args, code=code, operation_name=operation_name + client_error, *args, code=code, operation_name=operation_name # type: ignore ): matched = True if matched: @@ -180,7 +180,7 @@ def catch_aws_error( # Use a metaclass to hook into field access on the class class _ErrorsMeta(type): - def __getattr__(self, name) -> Exception: + def __getattr__(self, name) -> Type[BaseException]: if not sys.exc_info()[0]: raise RuntimeError( "You must use {}.{} inside an except statement".format( diff --git a/pyproject.toml b/pyproject.toml index 795e0a8..75c0ee9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "aws-error-utils" -version = "2.4.0" # update here and aws_error_utils.py +version = "2.5.0" # update here and aws_error_utils.py description = "Error-handling functions for boto3/botocore" authors = ["Ben Kehoe"] license = "Apache-2.0" @@ -24,6 +24,8 @@ dataclasses = { version = "*", python = "<3.7" } [tool.poetry.dev-dependencies] pylint = "*" pytest = "^6.2.5" +mypy = "^0.931" +types-dataclasses = { version = "*", python = "<3.7" } [build-system] requires = ["poetry>=0.12"]