biqqles / dataclassy

A fast and flexible reimplementation of data classes
https://pypi.org/project/dataclassy
Mozilla Public License 2.0
81 stars 9 forks source link

Custom init silences duplicate arguments #7

Closed biqqles closed 3 years ago

biqqles commented 3 years ago

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.

biqqles commented 3 years ago

Fixed and tests updated to catch this.