[Python-Dev] list.init() vs. dict.init() behaviour (original) (raw)
Guido van Rossum guido at python.org
Sat Jul 15 16:50:31 CEST 2006
- Previous message: [Python-Dev] list.__init__() vs. dict.__init__() behaviour
- Next message: [Python-Dev] Dynamic module namspaces
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 7/15/06, Stephen Thorne <stephen.thorne at gmail.com> wrote:
When testing some 'real world' code using pypy, an inconsistancy with the way init works between lists and dicts.
The assumption was made when implementing init for pypy that list.init and dict.init would both wipe the contents of the objects, but it seems that in cpython, this isn't precisely the case. >>> l = [2,3] >>> list.init(l) >>> l [] >>> d = {2: 3} >>> dict.init(d) >>> d {2: 3} dict.init(mydict) does not wipe the keys. list.init(mylist) wipes the lists contents.
I think it's an accident of implementation. I never thought about this from the POV of a subclass. Apparently dict.init() shares some code with dict.update(). Or does it do a merge without overwriting existing keys?
https://codespeak.net/issue/pypy-dev/issue240
Is there a good reason for this behaviour? It has broken my code (a subclass of dict that populates a key before calling the superclasses constructer, in the twisted codebase).
I think your code was skating on awfully thin ice by making any assumptions whatsoever about the base class constructor.
But I also think that this ought to be specified in the language spec. I'm not sure that consistency between list and dict is important to me, but they probably should both answer to some higher principle which I cannot formulate ATM.
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] list.__init__() vs. dict.__init__() behaviour
- Next message: [Python-Dev] Dynamic module namspaces
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]