@@ -63,14 +63,14 @@ def generate_rewrite(file: Path, source: str) -> None:
6363
6464 changed : list [Sequence [ast .AST ]] = []
6565 for parents , node in walk_with_parent (tree ):
66- if isinstance (node , ast .Call ):
66+ if isinstance (node , ast .Call ) and node . args :
6767 func = node .func
6868 if isinstance (func , ast .Attribute ):
6969 name = func .attr
7070 elif isinstance (func , ast .Name ):
7171 name = func .id
7272 else :
73- name = ""
73+ continue
7474 if hasattr (html , name ) or name == "vdom" :
7575 if name == "vdom" :
7676 maybe_attr_dict_node = node .args [1 ]
@@ -112,7 +112,7 @@ def generate_rewrite(file: Path, source: str) -> None:
112112 ):
113113 nodes_to_unparse .append (current_node )
114114 break
115- else :
115+ else : # pragma: no cover
116116 raise RuntimeError ("Failed to change code" )
117117
118118 # check if an nodes to rewrite contain eachother, pick outermost nodes
@@ -134,12 +134,11 @@ def generate_rewrite(file: Path, source: str) -> None:
134134 # there may be some content just before and after the content we're re-writing
135135 before_replacement = lines [node .lineno - 1 ][: node .col_offset ].lstrip ()
136136
137- if node .end_lineno is not None and node .end_col_offset is not None :
138- after_replacement = lines [node .end_lineno - 1 ][
139- node .end_col_offset :
140- ].strip ()
141- else :
142- after_replacement = ""
137+ after_replacement = (
138+ lines [node .end_lineno - 1 ][node .end_col_offset :].strip ()
139+ if node .end_lineno is not None and node .end_col_offset is not None
140+ else ""
141+ )
143142
144143 replacement = indent (
145144 before_replacement
@@ -148,10 +147,7 @@ def generate_rewrite(file: Path, source: str) -> None:
148147 " " * (node .col_offset - len (before_replacement )),
149148 )
150149
151- if node .end_lineno :
152- lines [node .lineno - 1 : node .end_lineno ] = [replacement ]
153- else :
154- lines [node .lineno - 1 ] = replacement
150+ lines [node .lineno - 1 : node .end_lineno or node .lineno ] = [replacement ]
155151
156152 if comments :
157153 moved_comment_lines_from_end .append (len (lines ) - node .lineno )
0 commit comments