Re: [Python-Dev] Proper way to specify that a method is not defined for a type

2016-06-07 Thread R. David Murray
For those interested in this topic, if you are not already aware of it, see also http://bugs.python.org/issue25958, which among other things has a relevant proposed patch for datamode.rst. On Tue, 07 Jun 2016 10:56:37 -0700, Guido van Rossum wrote: > Setting it to None in the subclass is the inte

Re: [Python-Dev] Proper way to specify that a method is not defined for a type

2016-06-07 Thread Guido van Rossum
Setting it to None in the subclass is the intended pattern. But CPython must explicitly handle that somewhere so I don't know how general it is supported. Try defining a list subclass with __len__ set to None and see what happens. Then try the same with MutableSequence. On Tue, Jun 7, 2016 at 10:3

Re: [Python-Dev] Proper way to specify that a method is not defined for a type

2016-06-07 Thread Émanuel Barry
> From: Ethan Furman > Sent: Tuesday, June 07, 2016 1:38 PM > To: Python Dev > Subject: [Python-Dev] Proper way to specify that a method is not defined for > a type (Just so everyone follows, this is a followup of http://bugs.python.org/issue27242 ) > For binary methods, such

[Python-Dev] Proper way to specify that a method is not defined for a type

2016-06-07 Thread Ethan Furman
For binary methods, such as __add__, either do not implement or return NotImplemented if the other operand/class is not supported. For non-binary methods, simply do not define. Except for subclasses when the super-class defines __hash__ and the subclass is not hashable -- then set __hash__ to