From a0668877446dbbe11f02adca5cbb7fa195ed9936 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Tue, 23 Jun 2020 11:16:58 -0300 Subject: [PATCH] Modified the macros examples to make them as similar as possible. So a diff between them is minimal. --- experiments/__doc__/macropy/try_mymacros.py | 2 +- experiments/__doc__/mcpy/application.py | 1 - experiments/__doc__/mcpy/mymacros.py | 10 +++++----- experiments/__doc__/mcpy/try_mymacros.py | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/experiments/__doc__/macropy/try_mymacros.py b/experiments/__doc__/macropy/try_mymacros.py index e5f1e6b7..beeabda1 100755 --- a/experiments/__doc__/macropy/try_mymacros.py +++ b/experiments/__doc__/macropy/try_mymacros.py @@ -1,3 +1,3 @@ #!/usr/bin/python3 import macropy.activate # noqa: F401 -import application # noqa: F401 +import application # noqa: F401 diff --git a/experiments/__doc__/mcpy/application.py b/experiments/__doc__/mcpy/application.py index 38084834..f9a7b66a 100644 --- a/experiments/__doc__/mcpy/application.py +++ b/experiments/__doc__/mcpy/application.py @@ -1,6 +1,5 @@ from mymacros import macros, document # noqa: F401 - with document: # comentario a a = "5.1" diff --git a/experiments/__doc__/mcpy/mymacros.py b/experiments/__doc__/mcpy/mymacros.py index 4baf01d1..53183b30 100644 --- a/experiments/__doc__/mcpy/mymacros.py +++ b/experiments/__doc__/mcpy/mymacros.py @@ -1,15 +1,15 @@ from ast import (Assign, Name, Attribute, Expr, Num, Str, NameConstant, Load, Store) -def document(sentences, to_source, **kw): +def document(tree, **kw): """ This macro takes literal strings and converts them into: _help_ID = type_hint+STRING where: ID is the first target of the last assignment. type_hint is the assigned type and default value (only works for a few types) STRING is the literal string """ - for n in range(len(sentences)): - s = sentences[n] + for n in range(len(tree)): + s = tree[n] if not n: prev = s continue @@ -48,7 +48,7 @@ def document(sentences, to_source, **kw): target = Attribute(value=Name(id='self', ctx=Load()), attr=doc_id, ctx=Store()) else: target = Name(id=doc_id, ctx=Store()) - sentences[n] = Assign(targets=[target], value=Str(s=type_hint+s.value.s)) + tree[n] = Assign(targets=[target], value=Str(s=type_hint+s.value.s)) prev = s # Return the modified AST - return sentences + return tree diff --git a/experiments/__doc__/mcpy/try_mymacros.py b/experiments/__doc__/mcpy/try_mymacros.py index 61dfb475..f7b184bb 100755 --- a/experiments/__doc__/mcpy/try_mymacros.py +++ b/experiments/__doc__/mcpy/try_mymacros.py @@ -1,3 +1,3 @@ #!/usr/bin/python3 import mcpy.activate # noqa: F401 -import application # noqa: F401 +import application # noqa: F401