[issue15879] set.__or__, __and__, etc create subclass types, but ignore __new__

Jon Obermark report at bugs.python.org
Fri Sep 7 17:44:41 CEST 2012


New submission from Jon Obermark:

If they are not going to call the __metaclass__ or the class __new__, then they should return `set` objects instead of subclass objects, so that it is clear what is going on.

As it is, the results of set operations receive some subclass information but not all.  So they are not really obeying the notion of a subclass: the results are neither `set` objects, nor properly-constructed objects of the `set` subclass.

e.g. 
class Fooset(Set):
  def __new__(cls, s = []):
    print 'New called'
    self = super(Fooset, cls).__new__(cls)
    self.update(s)
    if isinstance(s, Fooset):
      self.foo = s.foo
    else:
      self.foo = 'default'
    return self

x = Fooset([1,2,5])
y = x|x


The object `y` reports being of the type `Fooset`, but has not been constructed by the `type` that makes `Fooset` objects.

----------
messages: 169986
nosy: Jon.Obermark
priority: normal
severity: normal
status: open
title: set.__or__, __and__, etc create subclass types, but ignore __new__

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15879>
_______________________________________


More information about the Python-bugs-list mailing list