Skip to content
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 .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Package version](https://img.shields.io/pypi/v/flake8-type-checking.svg)](https://pypi.org/project/flake8-type-checking/)
[![Test status](https://github.com/snok/flake8-type-checking/actions/workflows/testing.yml/badge.svg)](https://github.com/snok/flake8-type-checking/actions/workflows/testing.yml)
[![Supported Python versions](https://img.shields.io/badge/python-3.9%2B-blue)](https://pypi.org/project/flake8-type-checking/)
[![Supported Python versions](https://img.shields.io/badge/python-3.10%2B-blue)](https://pypi.org/project/flake8-type-checking/)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
[![codecov](https://codecov.io/gh/snok/flake8-type-checking/graph/badge.svg?token=c0hqbAteWi)](https://codecov.io/gh/snok/flake8-type-checking)

Expand Down
7 changes: 5 additions & 2 deletions flake8_type_checking/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,8 +1542,11 @@ def visit_AnnAssign(self, node: ast.AnnAssign) -> None:
self.current_scope.symbols[node.target.id].append(
Symbol(
node.target.id,
node.target.lineno,
node.target.col_offset,
# We use the end of the statement for the position of the symbol so
# lexicographical lookups correctly only see the symbol after the end
# of the statement.
node.lineno if node.end_lineno is None else node.end_lineno,
node.col_offset if node.end_col_offset is None else node.end_col_offset,
(
# AnnAssign can omit the RHS, in which case it's just a declaration
# and doesn't result in a variable that's available at runtime
Expand Down
729 changes: 423 additions & 306 deletions poetry.lock

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ classifiers = [
'License :: OSI Approved :: BSD License',
'Topic :: Software Development :: Quality Assurance',
'Programming Language :: Python',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
Expand All @@ -30,21 +29,19 @@ classifiers = [
"Releases" = "https://github.com/snok/flake8-type-checking/releases"

[tool.poetry.dependencies]
python = '>=3.9'
python = '>=3.10'
flake8 = '*'
classify-imports = '*'

[tool.poetry.dev-dependencies]
[tool.poetry.plugins.'flake8.extension']
TC = 'flake8_type_checking.plugin:Plugin'

[tool.poetry.group.dev.dependencies]
pytest = '*'
ipython = '*'
coverage = '*'
pre-commit = '*'
pytest-flake8-path = '*'

[tool.poetry.plugins.'flake8.extension']
TC = 'flake8_type_checking.plugin:Plugin'

[tool.poetry.group.dev.dependencies]
flake8-bugbear = "^24.10.31"

[build-system]
Expand Down
2 changes: 2 additions & 0 deletions tests/test_tc007.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
("if TYPE_CHECKING:\n\tfrom typing import Dict\nx: TypeAlias = 'Dict'", set()),
("if TYPE_CHECKING:\n\tfrom typing import Dict as d\nx: TypeAlias = 'd[int]'", set()),
('if TYPE_CHECKING:\n\tfrom typing import Dict\nx: TypeAlias = Dict[int]', {'3:15 ' + TC007.format(alias='Dict')}),
# recursive type aliases should trigger TC007
('X: TypeAlias = Union[str, dict[str, X]]', {'1:36 ' + TC007.format(alias='X')}),
# Regression test for issue #163
(
textwrap.dedent('''
Expand Down
20 changes: 20 additions & 0 deletions tests/test_tc008.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"from __future__ import annotations\nif TYPE_CHECKING:\n\tfrom typing import Dict\nx: TypeAlias = Dict['int']",
{'4:20 ' + TC008.format(alias='int')},
),
# recursive type aliases should not trigger TC008
("X: TypeAlias = Union[str, dict[str, 'X']]", set()),
(
textwrap.dedent('''
from __future__ import annotations
Expand Down Expand Up @@ -88,6 +90,24 @@ class X(Protocol):
'''),
set(),
),
(
# Regression test for issue #209
textwrap.dedent('''
from __future__ import annotations

from collections.abc import Mapping
from typing import TYPE_CHECKING, Union, TypeAlias

MyTypeAlias: TypeAlias = Union[
bool,
str,
int,
float,
Mapping[str, "MyTypeAlias"],
]
'''),
set(),
),
]

if sys.version_info >= (3, 12):
Expand Down