Skip to content

Commit

Permalink
Add --allow-star-arg-any flag
Browse files Browse the repository at this point in the history
  • Loading branch information
sco1 committed Apr 4, 2022
1 parent a969176 commit ea1e59e
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ci:

repos:
- repo: /~https://github.com/psf/black
rev: 22.1.0
rev: 22.3.0
hooks:
- id: black
- repo: /~https://github.com/pycqa/isort
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
Versions follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html) (`<major>`.`<minor>`.`<patch>`)

## [v2.9.0]
### Added
* #135 Add `--allow-star-arg-any` to support suppression of `ANN401` for `*args` and `**kwargs`.

## [v2.8.0]
### Added
* #131 Add the `ANN4xx` error level for opinionated warnings that are disabled by default.
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ See: [The `typing.overload` Decorator](#the-typingoverload-decorator) for additi

Default: `"overload"`

### `--allow-star-arg-any`
Suppress `ANN401` for dynamically typed `*args` and `**kwargs`.

Default: `False`

## Generic Functions
Per the Python Glossary, a [generic function](https://docs.python.org/3/glossary.html#term-generic-function) is defined as:
Expand Down
14 changes: 11 additions & 3 deletions flake8_annotations/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self, tree: t.Optional[ast.Module], lines: t.List[str]):
self.allow_untyped_defs: bool
self.allow_untyped_nested: bool
self.mypy_init_return: bool
self.allow_star_arg_any: bool
self.dispatch_decorators: t.Set[str]
self.overload_decorators: t.Set[str]

Expand Down Expand Up @@ -168,9 +169,7 @@ def add_options(cls, parser: OptionManager) -> None: # pragma: no cover
default=False,
action="store_true",
parse_from_config=True,
help=(
"Suppress ANN000-level errors for dummy arguments, defined as '_'. (Default: %(default)s)" # noqa: E501
),
help="Suppress ANN000-level errors for dummy arguments, defined as '_'. (Default: %(default)s)", # noqa: E501
)

parser.add_option(
Expand Down Expand Up @@ -226,6 +225,14 @@ def add_options(cls, parser: OptionManager) -> None: # pragma: no cover
),
)

parser.add_option(
"--allow-star-arg-any",
default=False,
action="store_true",
parse_from_config=True,
help="Suppress ANN401 for dynamically typed *args and **kwargs. (Default: %(default)s)",
)

@classmethod
def parse_options(cls, options: Namespace) -> None: # pragma: no cover
"""Parse the custom configuration options given to flake8."""
Expand All @@ -234,6 +241,7 @@ def parse_options(cls, options: Namespace) -> None: # pragma: no cover
cls.allow_untyped_defs = options.allow_untyped_defs
cls.allow_untyped_nested = options.allow_untyped_nested
cls.mypy_init_return = options.mypy_init_return
cls.allow_star_arg_any = options.allow_star_arg_any

# Store decorator lists as sets for easier lookup
cls.dispatch_decorators = set(options.dispatch_decorators)
Expand Down
Loading

0 comments on commit ea1e59e

Please sign in to comment.