Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Jan 6, 2024
1 parent 635e0c0 commit 42e06f5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
16 changes: 13 additions & 3 deletions vyper/ast/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,19 @@ def annotate_python_ast(
resolved_path=resolved_path,
)
visitor.visit(parsed_ast)
for k, v in loop_var_annotations.items():
tokens = asttokens.ASTTokens(v["source_code"], tree=cast(Optional[python_ast.Module], v["parsed_ast"]))
visitor = AnnotatingVisitor(v["source_code"], {}, tokens, source_id, module_path=module_path, resolved_path=resolved_path)

for _, v in loop_var_annotations.items():
tokens = asttokens.ASTTokens(
v["source_code"], tree=cast(Optional[python_ast.Module], v["parsed_ast"])
)
visitor = AnnotatingVisitor(
v["source_code"],
{},
tokens,
source_id,
module_path=module_path,
resolved_path=resolved_path,
)
visitor.visit(v["parsed_ast"])

return parsed_ast
21 changes: 10 additions & 11 deletions vyper/ast/pre_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ def pre_parse(code: str) -> tuple[Settings, ModificationOffsets, str]:

if typ == NAME and string == "for":
is_for_loop = True
#print("for loop!")
#print(token)
# print("for loop!")
# print(token)

if is_for_loop:
if typ == NAME and string == "in":
loop_var_annotations[start[0]] = loop_var_annotation
Expand All @@ -170,7 +170,7 @@ def pre_parse(code: str) -> tuple[Settings, ModificationOffsets, str]:
continue

elif after_loop_var and not (typ == NAME and string == "for"):
#print("adding to loop var: ", toks)
# print("adding to loop var: ", toks)
loop_var_annotation.extend(toks)
continue

Expand All @@ -179,16 +179,15 @@ def pre_parse(code: str) -> tuple[Settings, ModificationOffsets, str]:
raise SyntaxException(e.args[0], code, e.args[1][0], e.args[1][1]) from e

for k, v in loop_var_annotations.items():


updated_v = untokenize(v)
#print("untokenized v: ", updated_v)
# print("untokenized v: ", updated_v)
updated_v = updated_v.replace("\\", "")
updated_v = updated_v.replace("\n", "")
import textwrap
#print("updated v: ", textwrap.dedent(updated_v))

# print("updated v: ", textwrap.dedent(updated_v))
loop_var_annotations[k] = {"source_code": textwrap.dedent(updated_v)}
#print("untokenized result: ", type(untokenize(result)))
#print("untokenized result decoded: ", untokenize(result).decode("utf-8"))

# print("untokenized result: ", type(untokenize(result)))
# print("untokenized result decoded: ", untokenize(result).decode("utf-8"))
return settings, modification_offsets, loop_var_annotations, untokenize(result).decode("utf-8")
2 changes: 1 addition & 1 deletion vyper/compiler/phases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import warnings
from functools import cached_property
from pathlib import Path, PurePath
from typing import Any, Optional
from typing import Optional

from vyper import ast as vy_ast
from vyper.codegen import module
Expand Down
8 changes: 4 additions & 4 deletions vyper/semantics/analysis/local.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional
from typing import Optional

from vyper import ast as vy_ast
from vyper.ast.metadata import NodeMetadata
Expand Down Expand Up @@ -354,10 +354,10 @@ def visit_For(self, node):
iter_annotation = loop_var_annotations.get(node.lineno).get("vy_ast")
if not iter_annotation:
raise StructureException("Iterator needs type annotation", node.iter)

iter_annotation_node = iter_annotation.body[0].value
iter_type = type_from_annotation(iter_annotation_node, DataLocation.MEMORY)
node.target._metadata["type"] = iter_type
node.target._metadata["type"] = iter_type

if isinstance(node.iter, vy_ast.Call):
# iteration via range()
Expand Down Expand Up @@ -480,7 +480,7 @@ def visit_For(self, node):
for typ, exc in zip(type_list, for_loop_exceptions)
),
)

def visit_If(self, node):
validate_expected_type(node.test, BoolT())
self.expr_visitor.visit(node.test, BoolT())
Expand Down

0 comments on commit 42e06f5

Please sign in to comment.