smell: fixes assert in container constructor.

This commit is contained in:
Romain Dorgueil
2018-08-11 07:33:11 +02:00
parent 3ea0952bd3
commit ba08931020
2 changed files with 19 additions and 2 deletions

View File

@ -66,8 +66,11 @@ class Service(Option):
class Container(dict):
def __new__(cls, *args, **kwargs):
if len(args) == 1:
assert not len(kwargs), 'only one usage at a time, my dear.'
if not (args[0]):
if len(kwargs):
raise ValueError(
'You can either use {} with one positional argument or with keyword arguments, not both.'
)
if not args[0]:
return super().__new__(cls)
if isinstance(args[0], cls):
return cls