Skip to content

Commit

Permalink
optimize getoptions
Browse files Browse the repository at this point in the history
  • Loading branch information
nggit committed Oct 21, 2023
1 parent c8faa8d commit d516f7d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 5 additions & 5 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def getcontents(
'\r\n'.join(headers),
data).encode('latin-1')

family = socket.AF_INET

if ':' in host:
if host == '::':
host = 'localhost'

family = socket.AF_INET6
else:
family = socket.AF_INET
host = '127.0.0.1'
else:
family = socket.AF_INET6

with socket.socket(family, socket.SOCK_STREAM) as sock:
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
Expand Down
10 changes: 6 additions & 4 deletions tremolo/tremolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,14 @@ def on_response(self, *args):

def getoptions(self, func):
options = {}
arg_count = func.__code__.co_argcount

if func.__defaults__ is not None:
options = dict(zip(
func.__code__.co_varnames[:len(func.__defaults__)],
func.__defaults__
))
arg_count -= len(func.__defaults__)

for i, name in enumerate(func.__code__.co_varnames[
arg_count:func.__code__.co_argcount]):
options[name] = func.__defaults__[i]

return options

Expand Down

0 comments on commit d516f7d

Please sign in to comment.