[New-bugs-announce] [issue11854] __or__, __and__, __sub__, and __xor__ instantiate subclass of set without calling __init__

Robert Burke report at bugs.python.org
Sat Apr 16 07:29:55 CEST 2011


New submission from Robert Burke <sharpobject at gmail.com>:

If you create a subclass of set but do not override __or__, __and__, __xor__, and __sub__, calling these functions will yield a new instance of your subclass.  The new instance will never have __init__ called on it.  Depending on what you expect __init__ to do, this can cause problems later on.

The simplest solution would be to make these functions work like list.__add__.  If you have two instances of some list subclass (foo and bar), type(foo.__add__(bar)) will just be list.

----------
files: demo
messages: 133880
nosy: Robert.Burke
priority: normal
severity: normal
status: open
title: __or__, __and__, __sub__, and __xor__ instantiate subclass of set without calling __init__
type: behavior
versions: Python 2.6
Added file: http://bugs.python.org/file21680/demo

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


More information about the New-bugs-announce mailing list