Skip to content

Commit d27be86

Browse files
authored
Release v3.1.1
2 parents ec8b88b + 30976ac commit d27be86

File tree

10 files changed

+130
-81
lines changed

10 files changed

+130
-81
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 3.1.0
2+
current_version = 3.1.1
33
commit = False
44

55
[bumpversion:file:README.md]

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ repos:
2727
- id: python-check-blanket-type-ignore
2828
exclude: "test_type_ignore.py"
2929
- repo: https://github.com/astral-sh/ruff-pre-commit
30-
rev: v0.4.2
30+
rev: v0.4.4
3131
hooks:
3232
- id: ruff
3333
- repo: local

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22
Versions follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html) (`<major>`.`<minor>`.`<patch>`)
33

4+
## [v3.1.1]
5+
### Changed
6+
* #167 Add module-level support for the `--respect-type-ignore` flag
7+
48
## [v3.1.0]
59
### Added
610
* #164 Add `--respect-type-ignore` to support suppression of errors for functions annotated with `type: ignore`

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# flake8-annotations
2-
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/flake8-annotations/3.1.0?logo=python&logoColor=FFD43B)](https://pypi.org/project/flake8-annotations/)
2+
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/flake8-annotations/3.1.1?logo=python&logoColor=FFD43B)](https://pypi.org/project/flake8-annotations/)
33
[![PyPI](https://img.shields.io/pypi/v/flake8-annotations?logo=Python&logoColor=FFD43B)](https://pypi.org/project/flake8-annotations/)
44
[![PyPI - License](https://img.shields.io/pypi/l/flake8-annotations?color=magenta)](https://github.com/sco1/flake8-annotations/blob/main/LICENSE)
55
[![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)
6-
[![Open in Visual Studio Code](https://img.shields.io/badge/Open%20in-VSCode.dev-blue)](https://github.dev/sco1/flake8-annotations)
76

87
`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.
98

@@ -32,7 +31,7 @@ cog.out(
3231
]]] -->
3332
```bash
3433
$ flake8 --version
35-
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
34+
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
3635
```
3736
<!-- [[[end]]] -->
3837

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

143142
### `--respect-type-ignore`
144-
Suppress linting errors for functions annotated with a `# type: ignore` comment.
143+
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)).
145144

146145
**NOTE:** Type ignore tags are not considered, e.g. `# type: ignore[arg-type]` is treated the same as `# type: ignore`.
146+
**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.
147147

148148
Default: `False`
149149

flake8_annotations/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.1.0"
1+
__version__ = "3.1.1"

flake8_annotations/checker.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def __init__(self, tree: t.Optional[ast.Module], lines: t.List[str]):
4343
# Type ignores are provided by ast at the module level & we'll need them later when deciding
4444
# whether or not to emit errors for a given function
4545
self._type_ignore_lineno = {ti.lineno for ti in self.tree.type_ignores}
46+
self._has_mypy_ignore_errors = "# mypy: ignore-errors" in lines[0] if lines else False
4647

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

115116
# Optionally respect a type: ignore comment
116117
# These are considered at the function level & tags are not considered
117-
if self.respect_type_ignore and (function.lineno in self._type_ignore_lineno):
118-
continue
118+
if self.respect_type_ignore:
119+
if function.lineno in self._type_ignore_lineno:
120+
# function-level ignore
121+
continue
122+
elif (1 in self._type_ignore_lineno) or (
123+
self._has_mypy_ignore_errors
124+
): # pragma: no branch
125+
# module-level ignore
126+
# lineno from ast is 1-indexed
127+
continue
119128

120129
# Yield explicit errors for arguments that are missing annotations
121130
for arg in function.get_missed_annotations():

0 commit comments

Comments
 (0)