Skip to content

Decorators with named parameters? #513

@tjprescott

Description

@tjprescott

Currently, it seems that decorators only accept arguments positionally. I'm wondering if it would be feasible/beneficial to support keyword arguments.

// 1 - Positional makes it hard to know the expected inputs when there are many options
@petDecorator("Fluffy", 10, "orange", "tuna")
...

// 2 - Makes it a lot easier to know what you are setting, and only set those parameters you care about.
@petDecorator(name: "Fluffy", age: 10, color: "orange", favoriteTreat: "tuna")
...

// 3 - Alternatively, you could just have many small decorators.
@petName("Fluffy") @petAge(10) @petColor("orange") @petFavoriteTreat("tuna")
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    design:neededA design request has been raised that needs a proposal

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions