3 ms·
For a property setter, you have to give the method the same name as the original property, otherwise it mysteriously breaks. Here for singledispatchmethod they
by kzrdude 4y ago
For a property setter, you have to give the method the same name as the original property, otherwise it mysteriously breaks. Here for singledispatchmethod they give it the name _. Why no consistency? Such things seem ad-hoc in python. (This criticism comes from an avid Python user.)
- ssl232 4y agoI guess to indicate that the method the @mydispatch.register() decorator wraps will not be added to the class namespace; it will only be accessible via the function wrapped by @singledispatchmethod. As is typical in Python, an underscore indicates an anonymous/unused name.
- kzrdude 4y agoThis explanation doesn't seem to cover the case with @property def foo(self) and the following @foo.setter def foo(self, value) - I wonder why the name of the foo.setter method matters, it doesn't make sense to me.