Skip to content

Conversation

da-woods
Copy link
Contributor

@da-woods da-woods commented Jan 3, 2021

Part of the attempt to split #3383 into more reasonable pieces. This includes #3961 by necessity (so will look a bit smaller if that is merged ahead of this PR)


  1. Relax some restriction on cdef class staticmethods/classmethods

    Where it isn't able to do the efficient thing it falls back to calling the builtin method staticmethod/classmethod.

    staticmethod/classmethod are only special-cased when the decorator is innermost. Fixes Combining @staticmethod with other decorators is broken #1434

  2. Fixes Decorated methods in cdef classes should be ordinary functions #1274

    Where a method is arbitrarily decorated we don't really know the type of the self argument - it's probably just the type of the cdef class, but it could be anything else. Therefore we produce a warning with the suggestion to type the self argument appropriately. This is hopefully fairly intuitive, preserves speed for the common case while allowing the less common case to be supported.

    Additionally adds a compiler option fused_types_arbitrary_decorators. With this enabled we produce a fused function with the self type either that of the cdef class, or object. This option supports both cases automatically but is off by default (since it's potentially an unexpected change). This would be mostly transparent to the user, but if they look hard they will be able to tell it's a fused function, mostly because the function has __getitem__ defined.

    I suspect it fixes
    classmethod is unable to decorate a callable that is function (and not method) #3072
    class-level classmethod() can only be called on a method_descriptor or instance method. #3044
    but the associated test-cases were large and fairly confusing

@da-woods da-woods force-pushed the arb_decorators_standalone branch from c0f5ce0 to 965e596 Compare January 3, 2021 17:37
@da-woods da-woods changed the title Support for arbitrary decorators on cdef class methods Support for arbitrary decorators on methods of cdef classes Jan 3, 2021
Copy link
Contributor

@mattip mattip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some failures for python3.5 about installing julyterlab widgets, not related to this PR.

I am not sure why the numpy_pythran_unit test failed.

@da-woods
Copy link
Contributor Author

I am not sure why the numpy_pythran_unit test failed.

serge-sans-paille/pythran#1706 - it's unrelated to this

da-woods added a commit to da-woods/cython that referenced this pull request Feb 27, 2021
Comment on lines 890 to 897
@property
def type_set_manually(self):
if self._type_set_manually:
return True
return bool(getattr(self.base_type, "name", False))
@type_set_manually.setter
def type_set_manually(self, value):
self._type_set_manually = value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like a work-around for some other place in the code that isn't smart enough to determine a type correctly.
Do you see a way to do this differently, without such a flag?

Copy link
Contributor Author

@da-woods da-woods May 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've replaced it with a flag stored on FuncDefNode which is probably the right place to store this information.

(Edit: doesn't work... I'll have another look at this...) works now

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.

Combining @staticmethod with other decorators is broken Decorated methods in cdef classes should be ordinary functions
3 participants