Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support documenting individual macro arguments #2073

Open
chrisp60 opened this issue Jan 24, 2025 · 1 comment
Open

Support documenting individual macro arguments #2073

chrisp60 opened this issue Jan 24, 2025 · 1 comment

Comments

@chrisp60
Copy link

Currently, you cannot add comments to individual macro arguments.

Current Example

{# This is fine #}
{% macro foo(bar, baz) -%}
 Foo is {{ bar }} and {{ baz }}
{%- endmacro %}

Featured Example

{# This is no good #}
{% macro foo(
    {# Describes foo #}
    bar,
    {# Describes more of foo #}
    baz
) -%}
 Foo is {{ bar }} and {{ baz }}
{%- endmacro %}

Why

Macros for large projects can grow to have many arguments, and the ability to document arguments can be a net positive.

Where

I originally requested this feature in rinja-rs/rinja#273, a consumer of jinja syntax in the rust ecosystem.

Maintainers agreed it would be nice, countering with the understandable concern of being incompatible with jinja itself. They asked me to bring it up here, just to gauge interest.

How

Skimming some of the parsing code, this seems like it would be a pain to implement. I would understand if the request is declined.

To be entirely honest, I do not have much experience in python and am unsure if I could reasonably implement it myself. Totally understand if this just isn't worth it.

@dorsma
Copy link

dorsma commented Feb 13, 2025

How about putting a comment at the top of the macro that describes what it does along with its arguments, similar to Python docstrings? This way keeps the macro signature clean, and there's no need to modify the template engine.

Example using Google style args:

{% macro foo(bar, baz) -%}
    {# 
    Describes foo

    Args:
        bar: Describes bar
        baz: Describes baz
    #}
    Foo is {{ bar }} and {{ baz }}
{%- endmacro %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants