Commit 8348a749 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

Move implementation details to argmap.py

parent f2012be4
......@@ -35,8 +35,8 @@
from random import random, choice, randint
from math import log
from inspect import isclass
from .utils.argmap import (argmap_decode, argmap_check, argmap_dict_to_list,
argmap_list_to_dict)
from .utils.argmap import (argmap_decode, argmap_check, argmap_unpack_dict,
argmap_unpack_list)
try:
from collections import OrderedDict
......@@ -125,10 +125,7 @@ class Canonical(object):
return item
def _unpack(self, item):
argmap = argmap_list_to_dict(item)
if len(argmap) == 2:
return argmap[None]
return argmap
return argmap_unpack_list(item)
def create(self):
return None
......@@ -517,10 +514,7 @@ class Args(Canonical):
def _check(self, item):
if argmap_check(item):
if hasattr(item, 'keys') and callable(item.keys):
arglist = argmap_dict_to_list(item)[:-1]
else:
arglist = item[:-1]
arglist = argmap_unpack_dict(item)
else:
try:
arglist = OrderedDict(item).items()
......
......@@ -304,3 +304,13 @@ def argmap_dict_to_list(argmap):
args, kw = argmap_unzip_dict(argmap)
return args + kw.items() + [ARGMAP_MAGIC]
def argmap_unpack_list(argmap):
kw = argmap_list_to_dict(argmap)
if len(kw) == 2:
return kw[None]
return kw
def argmap_unpack_dict(argmap):
if hasattr(argmap, 'keys') and callable(argmap.keys):
return argmap_dict_to_list(argmap)[:-1]
return argmap[:-1]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment