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

Function Decorators dropped when inheriting from gevent.local.local #1266

Closed
bpowers39 opened this Issue Aug 6, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@bpowers39

bpowers39 commented Aug 6, 2018

  • gevent version: 1.3.4
  • Python version: cPython 3.6.5
  • Operating System: Red Hat Enterprise Linux Server release 7.5 (Maipo)

Description:

Sometime between Gevent 1.1.0 and 1.3.4, decorators on classes inheriting from gevent.local.local are dropped. In the example below, the @staticmethod decorator on the class inheriting from gevent.local.local is missing, but the class inheriting from threading.local works as expected.

Test Case:

import threading
from gevent.local import local

class ThreadingClass(threading.local):
    @staticmethod
    def test_method(*args):
        print(args)

class GeventClass(local):
    @staticmethod
    def test_method(*args):
        print(args)

print("Thread Local")
t = ThreadingClass()
print("Static:")
ThreadingClass.test_method(1, 2, 3)
print("Instance:")
t.test_method(1, 2, 3)

print()
print()

print("Gevent Local")
g = GeventClass()
print("Static:")
GeventClass.test_method(1, 2, 3)
print("Instance:")
g.test_method(1, 2, 3)

Expected Result

The decorators on both ThreadingClass GeventClass work as intended when instances of each class type are created.

Thread Local
Static:
(1, 2, 3)
Instance:
(1, 2, 3)


Gevent Local
Static:
(1, 2, 3)
Instance:
(1, 2, 3)

Actual Result

The @staticmethod decorator on GeventClass is dropped when an instance of the class is created.

Thread Local
Static:
(1, 2, 3)
Instance:
(1, 2, 3)


Gevent Local
Static:
(1, 2, 3)
Instance:
(<__main__.GeventClass object at 0x7f66615a6a98>, 1, 2, 3)
@jamadden

This comment has been minimized.

Member

jamadden commented Aug 6, 2018

Thanks for the report! That's definitely a regression in 1.3. (The cause is that staticmethod objects are descriptors, which, when invoked, return a plain function object...which itself is also a descriptor that produces method objects when invoked.)

@jamadden jamadden added the bug label Aug 6, 2018

@jamadden jamadden closed this in eacc744 Aug 6, 2018

jamadden added a commit that referenced this issue Aug 6, 2018

Merge pull request #1267 from gevent/issue1266
Don't double-descriptor @staticmethod objects. Fixes #1266
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment