Modified to use fix_locations instead of a manual loop.

This commit is contained in:
Salvador E. Tropea 2020-10-23 19:50:13 -03:00
parent d72c4b446b
commit b08b1104f1
2 changed files with 4 additions and 4 deletions

View File

@ -1,5 +1,6 @@
from ast import (Assign, Name, Attribute, Expr, Num, Str, NameConstant, copy_location, walk)
from mcpyrate.quotes import macros, q, u, n, a # noqa: F401
from mcpyrate.astfixers import fix_locations
import mcpyrate # noqa: F401
@ -48,8 +49,7 @@ def document(tree, **kw):
with q as quoted:
n[name] = u[type_hint + s.value.s.rstrip()]
tree[index] = quoted[0]
for node in walk(tree[index]):
copy_location(node, s)
fix_locations(tree[index], s, mode="overwrite")
prev = s
# Return the modified AST
return tree

View File

@ -12,6 +12,7 @@ from ast import (Assign, Name, Attribute, Expr, Num, Str, NameConstant, Load, St
from .mcpyrate import unparse
from .mcpyrate.quotes import macros, q, u, n, a # noqa: F401
from .mcpyrate.splicing import splice_statements
from .mcpyrate.astfixers import fix_locations
from . import mcpyrate # noqa: F401
@ -79,8 +80,7 @@ def document(sentences, **kw):
name = 'self.'+doc_id if is_attr else doc_id
with q as quoted:
n[name] = u[type_hint+s.value.s.rstrip()+post_hint]
for node in walk(quoted[0]):
copy_location(node, s)
fix_locations(quoted[0], s, mode="overwrite")
sentences[index] = quoted[0]
else:
# Transform the string into an assign for _help_ID