From d7d83e3af87a3ca6c0e812cd92b35dd27c673a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=20=D0=9B=D0=B5=D0=B1=D0=B5=D0=B4?= =?UTF-8?q?=D0=B5=D0=B2?= Date: Mon, 29 Apr 2019 13:14:54 +0300 Subject: [PATCH] add support for annotated kwargs --- flake8_annotations_coverage/__init__.py | 2 +- flake8_annotations_coverage/ast_helpers.py | 5 ++++- tests/test_annotations_coverage.py | 5 +++++ tests/test_files/kwargs_annotated.py | 2 ++ 4 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 tests/test_files/kwargs_annotated.py diff --git a/flake8_annotations_coverage/__init__.py b/flake8_annotations_coverage/__init__.py index d18f409..ffcc925 100644 --- a/flake8_annotations_coverage/__init__.py +++ b/flake8_annotations_coverage/__init__.py @@ -1 +1 @@ -__version__ = '0.0.2' +__version__ = '0.0.3' diff --git a/flake8_annotations_coverage/ast_helpers.py b/flake8_annotations_coverage/ast_helpers.py index ddd1284..8654ee0 100644 --- a/flake8_annotations_coverage/ast_helpers.py +++ b/flake8_annotations_coverage/ast_helpers.py @@ -3,5 +3,8 @@ def has_type_annotations(func_def) -> bool: has_return_annotation = func_def.returns is not None has_args_annotations = any(a for a in func_def.args.args if a.annotation is not None) + has_kwargs_annotations = func_def.args and func_def.args.kwarg and func_def.args.kwarg.annotation is not None has_kwonly_args_annotations = any(a for a in func_def.args.kwonlyargs if a.annotation is not None) - return has_return_annotation or has_args_annotations or has_kwonly_args_annotations + return any( + (has_return_annotation, has_kwargs_annotations, has_args_annotations, has_kwonly_args_annotations), + ) diff --git a/tests/test_annotations_coverage.py b/tests/test_annotations_coverage.py index 02808bd..d02874e 100644 --- a/tests/test_annotations_coverage.py +++ b/tests/test_annotations_coverage.py @@ -25,3 +25,8 @@ def test_ok_for_kwonly_annotated_file(): assert not errors errors = run_validator_for_test_file('kwonly_arg_annotated.py', min_coverage=100) assert len(errors) == 1 + + +def test_ok_for_kwargs_annotated_file(): + errors = run_validator_for_test_file('kwargs_annotated.py') + assert not errors diff --git a/tests/test_files/kwargs_annotated.py b/tests/test_files/kwargs_annotated.py new file mode 100644 index 0000000..d963855 --- /dev/null +++ b/tests/test_files/kwargs_annotated.py @@ -0,0 +1,2 @@ +def foo(**kwargs: str): + pass