Skip to content

@function(cost=?) cannot be used inside of a class to decorate its functions #229

@shinawy

Description

@shinawy

I can't use the decorator @function inside of a class while using self or cls as the parameter of the function decorated. The following example gives an error.

import egglog as el 

# @dataclass
class Num(el.Expr):
    def __init__(self, value: el.i64Like) -> None:
        ...

    # This works
    @classmethod
    def var(cls, name: el.StringLike) -> Num:
        ...
     
    # this does not work
    @function (cost=10)
    def __add__(cls, other: Num) -> Num:
        ...

     # this does not work
    @function (cost=10)
    def __add__(self, other: Num) -> Num:
        ...

Is this considered an issue? If no, is there another way to set costs and other attributes for functions without using the function decorator?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions