Skip to content

Commit

Permalink
Release v2.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sco1 committed Apr 15, 2022
2 parents a969176 + c273045 commit 2044dc8
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 107 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.8.0
current_version = 2.9.0
commit = False

[bumpversion:file:pyproject.toml]
Expand Down
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
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cog.out(
]]] -->
```bash
$ flake8 --version
4.0.1 (flake8-annotations: 2.8.0, mccabe: 0.6.1, pycodestyle: 2.8.0, pyflakes:2.4.0) CPython 3.10.2 on Darwin
4.0.1 (flake8-annotations: 2.9.0, mccabe: 0.6.1, pycodestyle: 2.8.0, pyflakes:2.4.0) CPython 3.10.2 on Darwin
```
<!-- [[[end]]] -->

Expand Down Expand Up @@ -64,6 +64,7 @@ With the exception of `ANN4xx`-level warnings, all warnings are enabled by defau
| `ANN206` | Missing return type annotation for classmethod |

### Type Comments
**Deprecation notice**: Support for type comments will be removed in `3.0`. See [this issue](https://github.com/sco1/flake8-annotations/issues/95) for more information.
| ID | Description |
|----------|-----------------------------------------------------------|
| `ANN301` | PEP 484 disallows both type annotations and type comments |
Expand Down Expand Up @@ -136,6 +137,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 Expand Up @@ -189,6 +194,7 @@ Will not raise linting errors for missing annotations for the arguments & return
Decorator(s) to treat as `typing.overload` may be specified by the [`--overload-decorators`](#--overload-decorators-liststr) configuration option.

## Caveats for PEP 484-style Type Comments
**Deprecation notice**: Support for type comments will be removed in `3.0`. See [this issue](https://github.com/sco1/flake8-annotations/issues/95) for more information.
### Mixing argument-level and function-level type comments
Support is provided for mixing argument-level and function-level type comments.

Expand Down Expand Up @@ -235,8 +241,6 @@ def foo(arg1, arg2):
```
Will show `arg1` as missing a type hint.

**Deprecation notice**: Explicit support for utilization of ellipses as placeholders will be removed in version `3.0`. See [this issue](https://github.com/sco1/flake8-annotations/issues/95) for more information.

## Dynamic Typing Caveats
Support is only provided for the following patterns:
* `from typing import any; foo: Any`
Expand Down
2 changes: 1 addition & 1 deletion flake8_annotations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
else:
PY_GTE_38 = False

__version__ = "2.8.0"
__version__ = "2.9.0"
23 changes: 18 additions & 5 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 @@ -104,12 +105,17 @@ def run(self) -> t.Generator[FORMATTED_ERROR, None, None]:
yield error_codes.ANN301.from_function(function).to_flake8()
break

# Iterate over the annotated args to look for `typing.Any`` annotations
# Iterate over the annotated args to look for `typing.Any` annotations
# We could combine this with the above loop but I'd rather not add even more sentinels
# unless we'd notice a significant enough performance impact
for arg in annotated_args:
if arg.is_dynamically_typed:
# Always yield these and let flake8 take care of ignoring
if self.allow_star_arg_any and arg.annotation_type in {
enums.AnnotationType.VARARG,
enums.AnnotationType.KWARG,
}:
continue

yield error_codes.ANN401.from_argument(arg).to_flake8()

# Before we iterate over the function's missing annotations, check to see if it's the
Expand Down Expand Up @@ -168,9 +174,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 +230,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 +246,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 2044dc8

Please sign in to comment.