Skip to content
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

Fix classmethod wrapping #5826

Merged
merged 2 commits into from
Aug 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pubsub/google/cloud/pubsub_v1/_gapic.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def wrap(wrapped_fx):
# Similarly, for instance methods, we need to send self.api rather
# than self, since that is where the actual methods were declared.
instance_method = True

# If this is a bound method it's a classmethod.
self = getattr(wrapped_fx, '__self__', None)
if issubclass(type(self), type):
instance_method = False
Expand All @@ -41,8 +43,9 @@ def wrap(wrapped_fx):
if instance_method:
fx = lambda self, *a, **kw: wrapped_fx(self.api, *a, **kw) # noqa
return functools.wraps(wrapped_fx)(fx)
fx = lambda self, *a, **kw: wrapped_fx(*a, **kw) # noqa
return functools.wraps(wrapped_fx)(fx)

fx = lambda *a, **kw: wrapped_fx(*a, **kw) # noqa
return staticmethod(functools.wraps(wrapped_fx)(fx))

def actual_decorator(cls):
# Reflectively iterate over most of the methods on the source class
Expand Down