
On Mon, Nov 03, 2014 at 08:04:10PM -0800, Ethan Furman wrote:
On 11/03/2014 07:57 PM, Steven D'Aprano wrote:
I'm just crafting some tests to explore how NotImplemented impacts various classes, and the dunder versions make the whole thing much nicer.
I'm surprised. I can't imagine dunder names making anything look nicer. It sounds like you are writing "operator.__add__" instead of "operator.add", which doesn't look nicer to me.
The dunder versions are being used to check if a particular method is in a type's dictionary, to see how the subclass should be tailored for a test. Without the dunder versions I would have had to create my own mapping between dunder and dunderless names.
The dunder *methods* aren't going away. The dunder *functions* in operator won't be going away either. But even if they did, it is trivial to change: getattr(operator, op) # op looks like '__add__', etc. to getattr(operator, op.strip('_')) except of course for full generality you might need a mapping to cover cases where the operator function isn't the same as the dunder method. E.g. operator.truth, operator.contains. (I don't think they are relevant to your case though.) In any case, unless I'm missing something, I don't think that even full-blown removal of the dunder functions would affect your code in any significant way, and I'm not arguing for removal.
Can you show me your code?
Check out the "Role of NotImplemented" over on pydev. The script is the last half of the first post.
https://mail.python.org/pipermail/python-dev/2014-November/136875.html -- Steven