[issue26060] Class __dict__ iteration order changing due to type instance key-sharing

2020-09-11 Thread Brett Cannon


Change by Brett Cannon :


--
nosy:  -brett.cannon

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26060] Class __dict__ iteration order changing due to type instance key-sharing

2016-01-12 Thread Ionel Cristian Mărieș

Ionel Cristian Mărieș added the comment:

As I understood it the issue is not with the order but with the iteration being 
"unstable" (eg: same key appears multiple times). Yes, the dict is mutated 
while it's being iterated on, but no keys are added or removed, only values are 
changed.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26060] Class __dict__ iteration order changing due to type instance key-sharing

2016-01-12 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc added the comment:

Indeed. Here is another version of the script, it crashes when I set 
PYTHONHASHSEED=1 and passes with PYTHONHASHSEED=3::

class Meta(type):
def __new__(meta, clsname, bases, methods):
cls = super(Meta, meta).__new__(meta, clsname, bases, methods)
count = 0
for name in vars(cls):
if name.startswith('f_'):
print('decorate', name)
count += 1
setattr(cls, name, getattr(cls, name))
assert count == 8
return cls

class Spam2(metaclass=Meta):
def f_1(self): pass
def f_2(self): pass
def f_3(self): pass
def f_4(self): pass
def f_5(self): pass
def f_6(self): pass
def f_7(self): pass
def f_8(self): pass

--
nosy: +amaury.forgeotdarc

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26060] Class __dict__ iteration order changing due to type instance key-sharing

2016-01-09 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
nosy: +Mark.Shannon, benjamin.peterson, pingebretson, rhettinger, 
serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26060] Class __dict__ iteration order changing due to type instance key-sharing

2016-01-09 Thread Nick Coghlan

New submission from Nick Coghlan:

Dave Beazley found some odd behaviour in Python 3.4.1+, where the order of the 
keys in a class dictionary can be changed by assigning a new value to an 
existing key: https://gist.github.com/dabeaz/617a5b0542d57e003433

Dave's original reproducer showed a case where iterating over class attributes 
replacing some of them with new values worked correctly as a class decorator on 
a normal instance of type, but was unreliable when the same operation was 
called from a metaclass __new__ or __init__ method.

Further investigation showed that it wasn't the timing of the assignment that 
mattered, but rather the use of a subclass of type rather than type itself as 
the metaclass.

Checking between 3.4.0 and 3.4.1 with hg bisect using the simpler attached 
script as the reproducer identified the enabling of key sharing with subclass 
instances in #20637 as the apparent culprit.

My current theory is that from 3.3.0 to 3.4.0, keys weren't being shared 
between instances of type and instances of type subclasses at all, and changing 
that in 3.4.1 broke a subtle assumption somewhere in type_new.

--
files: ns_reordering_bug.py
messages: 257824
nosy: ncoghlan
priority: normal
severity: normal
status: open
title: Class __dict__ iteration order changing due to type instance key-sharing
Added file: http://bugs.python.org/file41550/ns_reordering_bug.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26060] Class __dict__ iteration order changing due to type instance key-sharing

2016-01-09 Thread Yury Selivanov

Changes by Yury Selivanov :


--
nosy: +yselivanov

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26060] Class __dict__ iteration order changing due to type instance key-sharing

2016-01-09 Thread Ionel Cristian Mărieș

Changes by Ionel Cristian Mărieș :


--
nosy: +ionelmc

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26060] Class __dict__ iteration order changing due to type instance key-sharing

2016-01-09 Thread Brett Cannon

Changes by Brett Cannon :


--
nosy: +brett.cannon

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26060] Class __dict__ iteration order changing due to type instance key-sharing

2016-01-09 Thread Brett Cannon

Changes by Brett Cannon :


--
nosy: +beazley

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26060] Class __dict__ iteration order changing due to type instance key-sharing

2016-01-09 Thread Emanuel Barry

Changes by Emanuel Barry :


--
nosy: +ebarry

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com