Following on from the example in #6, this currently works: s = State(7, path=1).
s.path is 1, but that's not obvious, and it would normally cause TypeError: __new__() got multiple values for argument 'path' as it does if __init__ is not defined.
The solution to this could be making all the arguments in __new__ keyword only, then in __call__ converting positional arguments destined for it into keyword arguments. Removing *args from __new__ means that duplicated positional arguments will not be silently passed back to __call__ and will instead raise the normal exception. Since __new__ is (normally) never called by the user directly, this would also be fully backwards compatible.
Following on from the example in #6, this currently works:
s = State(7, path=1)
.s.path
is1
, but that's not obvious, and it would normally causeTypeError: __new__() got multiple values for argument 'path'
as it does if__init__
is not defined.The solution to this could be making all the arguments in
__new__
keyword only, then in__call__
converting positional arguments destined for it into keyword arguments. Removing*args
from__new__
means that duplicated positional arguments will not be silently passed back to__call__
and will instead raise the normal exception. Since__new__
is (normally) never called by the user directly, this would also be fully backwards compatible.