Skip to content

Commit afc88fa

Browse files
committed
Type annotation tidying
1 parent 0aacdec commit afc88fa

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ coverage.xml
4141
cov.xml
4242
htmlcov
4343
.pytest_cache/
44+
45+
# mypy
46+
.mypy_cache/

flake8_annotations/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from itertools import zip_longest
3-
from typing import List, Union
3+
from typing import List, Set, Union
44

55
from flake8_annotations.enums import AnnotationType, ClassDecoratorType, FunctionType
66

@@ -305,8 +305,8 @@ class FunctionVisitor(ast.NodeVisitor):
305305

306306
def __init__(self, lines: List[str]):
307307
self.lines = lines
308-
self.function_definitions = []
309-
self._context = []
308+
self.function_definitions: List[Function] = []
309+
self._context: List[AST_DEF_NODES] = []
310310

311311
def switch_context(self, node: AST_DEF_NODES) -> None:
312312
"""
@@ -354,8 +354,8 @@ class ReturnVisitor(ast.NodeVisitor):
354354

355355
def __init__(self, parent_node: AST_FUNCTION_TYPES):
356356
self.parent_node = parent_node
357-
self._context = []
358-
self._non_none_return_nodes = set()
357+
self._context: List[AST_FUNCTION_TYPES] = []
358+
self._non_none_return_nodes: Set[AST_FUNCTION_TYPES] = set()
359359

360360
@property
361361
def has_only_none_returns(self) -> bool:

flake8_annotations/checker.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from argparse import Namespace
22
from functools import lru_cache
3-
from typing import Generator, List
3+
from typing import Generator, List, Tuple
44

55
from flake8.options.manager import OptionManager
66
from flake8_annotations import (
@@ -20,6 +20,8 @@
2020
else:
2121
from typed_ast import ast3 as ast
2222

23+
FORMATTED_ERROR = Tuple[int, int, str, error_codes.Error]
24+
2325

2426
class TypeHintChecker:
2527
"""Top level checker for linting the presence of type hints in function definitions."""
@@ -32,8 +34,9 @@ def __init__(self, tree: ast.Module, lines: List[str]):
3234
# Request `lines` here and join to allow for correct handling of input from stdin
3335
self.lines = lines
3436
self.tree = self.get_typed_tree("".join(lines)) # flake8 doesn't strip newlines
37+
self.suppress_none_returning: bool # Set by flake8's config parser
3538

36-
def run(self) -> Generator[error_codes.Error, None, None]:
39+
def run(self) -> Generator[FORMATTED_ERROR, None, None]:
3740
"""
3841
This method is called by flake8 to perform the actual check(s) on the source code.
3942

0 commit comments

Comments
 (0)