GrahamDumpleton / wrapt

A Python module for decorators, wrappers and monkey patching.
BSD 2-Clause "Simplified" License
2.04k stars 230 forks source link

use wrapt success in .py, but failed in .pyd #173

Closed youmeiyougc closed 3 years ago

youmeiyougc commented 3 years ago
from wrapt import decorator

@decorator
def d1(wrapped, instance, args, kwargs):
    print(f'd1: {args}, {kwargs}')
    return wrapped(*args, **kwargs)

def d2(*argsT, **kwargsT):
    @decorator
    def d3(wrapped, instance, args, kwargs):
        print(f'd3: {argsT}, {kwargsT}, {args}, {kwargs}')
        return wrapped(*args, **kwargs)
    return d3

@d1
@d2(a=int, b=str)
def hello():
    print('hello')

Save above code as hello.py, use another module, import hello and call hello.hello(), all success. Rename hello.py to hello.pyx, run "easycython hello.pyx" ,it generate hello.pyd, import again, raise TypeError. Is anyone has the same probrom?

2

1

GrahamDumpleton commented 3 years ago

Have you asked the cython community?

youmeiyougc commented 3 years ago

Have you asked the cython community?

No, it seems all right except nested decorator. I'll post the same issue to them, thanks.

GrahamDumpleton commented 3 years ago

Can you add a link here to where you asked the question about it?

youmeiyougc commented 3 years ago

Can you add a link here to where you asked the question about it? Ok. https://github.com/cython/cython/issues/4036#issue-831495143

da-woods commented 3 years ago

I think we've established this is a Cython bug and merged a fix for this. I doubt there's too much that you can sensibly do to work around it in wrapt.