Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v3.1.1 #168

Merged
merged 3 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = 3.1.0
current_version = 3.1.1
commit = False

[bumpversion:file:README.md]
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repos:
- id: python-check-blanket-type-ignore
exclude: "test_type_ignore.py"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.2
rev: v0.4.4
hooks:
- id: ruff
- repo: local
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>`)

## [v3.1.1]
### Changed
* #167 Add module-level support for the `--respect-type-ignore` flag

## [v3.1.0]
### Added
* #164 Add `--respect-type-ignore` to support suppression of errors for functions annotated with `type: ignore`
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# flake8-annotations
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/flake8-annotations/3.1.0?logo=python&logoColor=FFD43B)](https://pypi.org/project/flake8-annotations/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/flake8-annotations/3.1.1?logo=python&logoColor=FFD43B)](https://pypi.org/project/flake8-annotations/)
[![PyPI](https://img.shields.io/pypi/v/flake8-annotations?logo=Python&logoColor=FFD43B)](https://pypi.org/project/flake8-annotations/)
[![PyPI - License](https://img.shields.io/pypi/l/flake8-annotations?color=magenta)](https://github.com/sco1/flake8-annotations/blob/main/LICENSE)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/sco1/flake8-annotations/main.svg)](https://results.pre-commit.ci/latest/github/sco1/flake8-annotations/main)
[![Open in Visual Studio Code](https://img.shields.io/badge/Open%20in-VSCode.dev-blue)](https://github.dev/sco1/flake8-annotations)

`flake8-annotations` is a plugin for [Flake8](http://flake8.pycqa.org/en/latest/) that detects the absence of [PEP 3107-style](https://www.python.org/dev/peps/pep-3107/) function annotations.

Expand Down Expand Up @@ -32,7 +31,7 @@ cog.out(
]]] -->
```bash
$ flake8 --version
7.0.0 (flake8-annotations: 3.1.0, mccabe: 0.7.0, pycodestyle: 2.11.1, pyflakes: 3.2.0) CPython 3.12.3 on Darwin
7.0.0 (flake8-annotations: 3.1.1, mccabe: 0.7.0, pycodestyle: 2.11.1, pyflakes: 3.2.0) CPython 3.12.3 on Darwin
```
<!-- [[[end]]] -->

Expand Down Expand Up @@ -141,9 +140,10 @@ Suppress `ANN401` for dynamically typed `*args` and `**kwargs`.
Default: `False`

### `--respect-type-ignore`
Suppress linting errors for functions annotated with a `# type: ignore` comment.
Suppress linting errors for functions annotated with a `# type: ignore` comment. Support is also provided for module-level blanket ignores (see: [mypy: Ignoring a whole file](https://mypy.readthedocs.io/en/stable/common_issues.html#ignoring-a-whole-file)).

**NOTE:** Type ignore tags are not considered, e.g. `# type: ignore[arg-type]` is treated the same as `# type: ignore`.
**NOTE:** Module-level suppression is only considered for the `# mypy: ignore-errors` or `# type: ignore` tags when provided as the sole contents of the first line of the module.

Default: `False`

Expand Down
2 changes: 1 addition & 1 deletion flake8_annotations/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.1.0"
__version__ = "3.1.1"
13 changes: 11 additions & 2 deletions flake8_annotations/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, tree: t.Optional[ast.Module], lines: t.List[str]):
# Type ignores are provided by ast at the module level & we'll need them later when deciding
# whether or not to emit errors for a given function
self._type_ignore_lineno = {ti.lineno for ti in self.tree.type_ignores}
self._has_mypy_ignore_errors = "# mypy: ignore-errors" in lines[0] if lines else False

# Set by flake8's config parser
self.suppress_none_returning: bool
Expand Down Expand Up @@ -114,8 +115,16 @@ def run(self) -> t.Generator[FORMATTED_ERROR, None, None]:

# Optionally respect a type: ignore comment
# These are considered at the function level & tags are not considered
if self.respect_type_ignore and (function.lineno in self._type_ignore_lineno):
continue
if self.respect_type_ignore:
if function.lineno in self._type_ignore_lineno:
# function-level ignore
continue
elif (1 in self._type_ignore_lineno) or (
self._has_mypy_ignore_errors
): # pragma: no branch
# module-level ignore
# lineno from ast is 1-indexed
continue

# Yield explicit errors for arguments that are missing annotations
for arg in function.get_missed_annotations():
Expand Down
Loading
Loading