Skip to content

Block macro outputting a single-item body #7

Description

@Technologicat

It would be convenient if a block macro could return, when appropriate for some particular use case, just a single AST node as the transformed body. Currently the return type from a block macro must be list.

A real use case for this is the autocurry macro in unpythonic. (Usage, implementation.)

Minimal (non-)working example:

main.py:

from mwe import macros, mwe

with mwe:
    print("hi")
    print("ho")

mwe.py:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from macropy.core.macros import Macros

macros = Macros()

@macros.block
def mwe(tree, **kw):
    return tree[0]  # return just one AST node --> crash

[edit] update link.
[edit] update doc link.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions