Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
domdfcoding committed Jun 6, 2022
1 parent 7fbbe1b commit a6519c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
17 changes: 10 additions & 7 deletions astatine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
__version__: str = "0.3.2"
__email__: str = "dominic@davis-foster.co.uk"

__all__ = [
__all__ = (
"get_docstring_lineno",
"get_toplevel_comments",
"is_type_checking",
Expand All @@ -74,7 +74,7 @@
"get_attribute_name",
"get_contextmanagers",
"get_constants",
]
)


def get_toplevel_comments(source: str) -> StringList:
Expand Down Expand Up @@ -133,7 +133,7 @@ def mark_text_ranges(node: ast.AST, source: str) -> None:

ASTTokens(source, tree=node)

for child in ast.walk(node):
for child in ast.walk(node): # pylint: disable=dotted-import-in-loop
if hasattr(child, "last_token"):
child.end_lineno, child.end_col_offset = child.last_token.end # type: ignore[attr-defined]

Expand Down Expand Up @@ -260,12 +260,15 @@ def get_constants(module: ast.Module) -> Dict[str, Any]:

constants = {}

AssignNode = ast.Assign
literal_eval = ast.literal_eval

for node in module.body:
if isinstance(node, ast.Assign):
targets = ['.'.join(get_attribute_name(t)) for t in node.targets]
value = ast.literal_eval(node.value)
if isinstance(node, AssignNode):
targets = ['.'.join(get_attribute_name(t)) for t in node.targets] # pylint: disable=W8201
value = literal_eval(node.value)

for target in targets:
for target in targets: # pylint: disable=use-dict-comprehension
constants[target] = value

return constants
8 changes: 4 additions & 4 deletions tests/test_astatine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import ast
import sys
from types import ModuleType
from typing import Union
from typing import Any, Dict, Union

# 3rd party
import pytest
Expand Down Expand Up @@ -82,7 +82,7 @@ def test_is_type_checking(source: str, expected: bool):

class Visitor(ast.NodeVisitor):

def visit_If(self, node: ast.If):
def visit_If(self, node: ast.If) -> None:
print(node, node.test)
assert is_type_checking(node) is expected

Expand Down Expand Up @@ -218,7 +218,7 @@ def test_mark_text_ranges(source: str, advanced_data_regression: AdvancedDataReg
# TODO: check the output


def demo_function(arg1, arg2, arg3):
def demo_function(arg1, arg2, arg3): # noqa: MAN001,MAN002
pass


Expand All @@ -229,7 +229,7 @@ def demo_function(arg1, arg2, arg3):
("foo(1, 2, 3)", demo_function, {"arg1": 1, "arg2": 2, "arg3": 3}),
]
)
def test_kwargs_from_node(source, posarg_names, expects):
def test_kwargs_from_node(source: str, posarg_names: Any, expects: Dict[str, Any]):
tree = ast.parse(source)
node = tree.body[0].value # type: ignore[attr-defined]

Expand Down

0 comments on commit a6519c7

Please sign in to comment.