@@ -63,14 +63,14 @@ def generate_rewrite(file: Path, source: str) -> None:
63
63
64
64
changed : list [Sequence [ast .AST ]] = []
65
65
for parents , node in walk_with_parent (tree ):
66
- if isinstance (node , ast .Call ):
66
+ if isinstance (node , ast .Call ) and node . args :
67
67
func = node .func
68
68
if isinstance (func , ast .Attribute ):
69
69
name = func .attr
70
70
elif isinstance (func , ast .Name ):
71
71
name = func .id
72
72
else :
73
- name = ""
73
+ continue
74
74
if hasattr (html , name ) or name == "vdom" :
75
75
if name == "vdom" :
76
76
maybe_attr_dict_node = node .args [1 ]
@@ -112,7 +112,7 @@ def generate_rewrite(file: Path, source: str) -> None:
112
112
):
113
113
nodes_to_unparse .append (current_node )
114
114
break
115
- else :
115
+ else : # pragma: no cover
116
116
raise RuntimeError ("Failed to change code" )
117
117
118
118
# check if an nodes to rewrite contain eachother, pick outermost nodes
@@ -134,12 +134,11 @@ def generate_rewrite(file: Path, source: str) -> None:
134
134
# there may be some content just before and after the content we're re-writing
135
135
before_replacement = lines [node .lineno - 1 ][: node .col_offset ].lstrip ()
136
136
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
+ )
143
142
144
143
replacement = indent (
145
144
before_replacement
@@ -148,10 +147,7 @@ def generate_rewrite(file: Path, source: str) -> None:
148
147
" " * (node .col_offset - len (before_replacement )),
149
148
)
150
149
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 ]
155
151
156
152
if comments :
157
153
moved_comment_lines_from_end .append (len (lines ) - node .lineno )
0 commit comments