-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Support for arbitrary decorators on methods of cdef classes #3966
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
base: master
Are you sure you want to change the base?
Conversation
Also fix issue due to change to calling convention
(but with the property-related changes cut out)
c0f5ce0
to
965e596
Compare
There was a problem hiding this 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.
serge-sans-paille/pythran#1706 - it's unrelated to this |
Cython/Compiler/Nodes.py
Outdated
@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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Removed the property of the type in favour of keeping track of this for FuncDefNode
The pure Python behaviour has changed so the tests need to capture that.
(and run if-statement only once)
…arb_decorators_standalone
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)
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
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 thecdef 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 theself
type either that of thecdef class
, orobject
. 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 afused
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