Skip to content

Conversation

@Davda-James
Copy link
Contributor

@Davda-James Davda-James commented Jan 30, 2026

Now function decorator can support the class members methods as well along with standalone.

Closes issue: #1555
Files affected:

op.py
__init__.py

Added tests to test the behaviour for new support.

test_function_decorator_methods.py

example taken from tests added below (one):

def test_valid_decorations_do_not_raise_and_set_op_kind() -> None:
    class C:
        @coco.function()
        def im(self, scope=None):  # type: ignore[no-untyped-def]
            pass

        @classmethod
        @coco.function()
        def cm(cls, scope=None):  # type: ignore[no-untyped-def]
            pass

        @coco.function()
        @classmethod
        def cm2(cls, scope=None):  # type: ignore[no-untyped-def]
            pass

        @staticmethod
        @coco.function()
        def sm(scope=None):  # type: ignore[no-untyped-def]
            pass

        @coco.function()
        @staticmethod
        def sm2(scope=None):  # type: ignore[no-untyped-def]
            pass

    assert C.__dict__["im"].__cocoindex_op_kind__ == "Im"
    assert C.__dict__["cm"].__func__.__cocoindex_op_kind__ == "Cm"
    assert C.__dict__["cm2"].__func__.__cocoindex_op_kind__ == "Cm2"
    assert C.__dict__["sm"].__func__.__cocoindex_op_kind__ == "Sm"
    assert C.__dict__["sm2"].__func__.__cocoindex_op_kind__ == "Sm2"

Tests

  • all tests are passing

@georgeh0 pls review it whenever you get a chance. I appreciate any feedback or suggestions to improve this PR.

@georgeh0
Copy link
Member

Hi @Davda-James,

Thanks for making the PR!

Note that the issue #1555 is for CocoIndex v1 (under pre-release now). Please make changes from the v1 branch and merge changes into that branch.

Also there's a few updates since I filed the issue, and I made a comment.

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

Successfully merging this pull request may close these issues.

2 participants