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

Add separate method to derive function signature args #192

Merged
merged 1 commit into from
Aug 17, 2017
Merged
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions nsq/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ def _create_struct(fmt):
from cgi import parse_qs

try:
from inspect import getargspec as signature
except ImportError:
from inspect import signature
def func_args(func):
items = signature(func).parameters.values()
return [param.name for param in items
if param.kind == param.POSITIONAL_OR_KEYWORD]
except ImportError:
# inspect.getargspec is deprecated since 3.5
from inspect import getargspec
def func_args(func):
return getargspec(func).args
4 changes: 2 additions & 2 deletions nsq/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from ._compat import urlencode
from ._compat import urlparse
from ._compat import parse_qs
from ._compat import signature
from ._compat import func_args
from .backoff_timer import BackoffTimer
from .client import Client
from . import protocol
Expand Down Expand Up @@ -208,7 +208,7 @@ def __init__(
self.random_rdy_ts = time.time()

# Verify keyword arguments
valid_args = signature(async.AsyncConn.__init__)[0]
valid_args = func_args(async.AsyncConn.__init__)
diff = set(kwargs) - set(valid_args)
assert len(diff) == 0, 'Invalid keyword argument(s): %s' % list(diff)

Expand Down
4 changes: 2 additions & 2 deletions nsq/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import random

from ._compat import string_types
from ._compat import signature
from ._compat import func_args
from .client import Client
from nsq import protocol
from . import async
Expand Down Expand Up @@ -96,7 +96,7 @@ def __init__(self, nsqd_tcp_addresses, reconnect_interval=15.0, name=None, **kwa
self.conns = {}

# Verify keyword arguments
valid_args = signature(async.AsyncConn.__init__)[0]
valid_args = func_args(async.AsyncConn.__init__)
diff = set(kwargs) - set(valid_args)
assert len(diff) == 0, 'Invalid keyword argument(s): %s' % list(diff)

Expand Down