def __init__(self, constructors, name, *args, **kwargs):
args = tuple(map(self._unwrap_name, args))
kwargs = valmap(self._unwrap_name, kwargs)
already_bound = {}
for n, arg in enumerate(args):
if arg in already_bound:
raise TypeError(
'argument %r at position %d is already bound to the'
' positional argument at index %d' % (
arg,
n,
already_bound[arg],
),
)
already_bound[arg] = n
for k, arg in kwargs.items():
if arg in already_bound:
loc = already_bound[arg]
raise TypeError(
'argument %r at keyword %s is already bound to the %s' % (
arg,
k,
('positional argument at index %d' % loc)
if isinstance(loc, int) else
('keyword argument %r' % loc),
),
)
super().__init__(constructors, name, *args, **kwargs)
del constructors[name]
self._constructors = constructors
评论列表
文章目录