[issue24726] OrderedDict has strange behaviour when dict.__setitem__ is used.

2019-08-29 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
resolution:  -> wont fix
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue24726] OrderedDict has strange behaviour when dict.__setitem__ is used.

2019-08-24 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
assignee: rhettinger -> 

___
Python tracker 

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



[issue24726] OrderedDict has strange behaviour when dict.__setitem__ is used.

2019-08-23 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

See also:  https://bugs.python.org/msg131551

--

___
Python tracker 

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



[issue24726] OrderedDict has strange behaviour when dict.__setitem__ is used.

2019-08-22 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

There may still be some holes still remaining in OrderedDict but it doesn't 
seem to have been relevant in practice and will become even less so now that 
regular dicts are ordered and compact.  

If an issue does are arise with someone setting OrderedDict values via 
dict.__setitem__ we should probably just document "don't do that" rather than 
performing brain surgery on the current implementation which was known in 
advance to be vulnerable to exactly this sort of trickery.

If there are no objections, I recommend closing this as out-of-date.   IMO this 
would be better than risking introducing new problems are getting the C version 
further out of sync with the Python version or altering how existing code is 
working.

--
priority: normal -> low

___
Python tracker 

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



[issue24726] OrderedDict has strange behaviour when dict.__setitem__ is used.

2015-12-23 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here is a patch that fixes an infinite loop reported in msg254071. May be this 
is not the best solution. It makes the behavior of Python and C implementation 
differ (the former just iterates a linked list, the latter raises an error). 
But to reproduce Python implementation behavior we need to add refcounters to 
linked list nodes.

--
stage: commit review -> patch review
Added file: http://bugs.python.org/file41398/odict_delitem_iter_hung.patch

___
Python tracker 

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



[issue24726] OrderedDict has strange behaviour when dict.__setitem__ is used.

2015-11-06 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 1594c23d8c2f by Serhiy Storchaka in branch '3.5':
Issue #24726: Revert setting the value on the dict if
https://hg.python.org/cpython/rev/1594c23d8c2f

New changeset b391e97ccfe5 by Serhiy Storchaka in branch 'default':
Issue #24726: Revert setting the value on the dict if
https://hg.python.org/cpython/rev/b391e97ccfe5

--

___
Python tracker 

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



[issue24726] OrderedDict has strange behaviour when dict.__setitem__ is used.

2015-11-06 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Wrong issue. The correct one is issue25410.

--

___
Python tracker 

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



[issue24726] OrderedDict has strange behaviour when dict.__setitem__ is used.

2015-11-04 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thanks for your review Eric.

test_delitem_2 was not added because it fails in just added TestCase for 
COrderedDict subclass. Added tests for direct calls of other dict methods as 
Eric suggested.

During writing new tests for direct calls of other dict methods I found yet one 
bug. Following code makes Python to hang and eat memory.

from collections import OrderedDict
od = OrderedDict()
for i in range(10):
od[str(i)] = i

for i in range(9):
dict.__delitem__(od, str(i))

list(od)

--

___
Python tracker 

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



[issue24726] OrderedDict has strange behaviour when dict.__setitem__ is used.

2015-11-04 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Ping.

--

___
Python tracker 

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



[issue24726] OrderedDict has strange behaviour when dict.__setitem__ is used.

2015-10-21 Thread Eric Snow

Eric Snow added the comment:

FTR, this will likely involve more than just fixing odict_repr().

--

___
Python tracker 

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



[issue24726] OrderedDict has strange behaviour when dict.__setitem__ is used.

2015-10-21 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue24726] OrderedDict has strange behaviour when dict.__setitem__ is used.

2015-10-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

__repr__() allocates a list with the size len(od) and fills it iterating linked 
list. If the size of linked list is less then the size of the dict, the rest of 
the list is not initialized.

Even worse things happened when the size of linked list is greater then the 
size of the dict. Following example causes a crash:

from collections import OrderedDict
od = OrderedDict()
class K(str):
def __hash__(self):
return 1

od[K('a')] = 1
od[K('b')] = 2
print(len(od), len(list(od)))
K.__eq__ = lambda self, other: True
dict.__delitem__(od, K('a'))
print(len(od), len(list(od)))
print(repr(od))

Proposed patch fixes both issues.

--
components: +Extension Modules -Library (Lib)
keywords: +patch
stage: test needed -> patch review
type: behavior -> crash
versions:  -Python 2.7, Python 3.4
Added file: 
http://bugs.python.org/file40834/odict_repr_after_dict_setitem_delitem.patch

___
Python tracker 

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



[issue24726] OrderedDict has strange behaviour when dict.__setitem__ is used.

2015-07-31 Thread Terry J. Reedy

Terry J. Reedy added the comment:

Attached revised file that runs to completion on 2.7 and 3.x.

--
nosy: +terry.reedy
stage:  - test needed
versions: +Python 2.7, Python 3.4, Python 3.5
Added file: http://bugs.python.org/file40089/tem2.py

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



[issue24726] OrderedDict has strange behaviour when dict.__setitem__ is used.

2015-07-31 Thread Terry J. Reedy

Terry J. Reedy added the comment:

Marco, #-prefixed issue numbers like this, #24721, #24667, and #24685, are 
easier to read.

--

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



[issue24726] OrderedDict has strange behaviour when dict.__setitem__ is used.

2015-07-31 Thread Raymond Hettinger

Changes by Raymond Hettinger raymond.hettin...@gmail.com:


--
assignee:  - rhettinger

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



[issue24726] OrderedDict has strange behaviour when dict.__setitem__ is used.

2015-07-31 Thread Raymond Hettinger

Raymond Hettinger added the comment:

There is a bug in _PyObject_GenericSetAttrWithDict() Objects/object.c   where a 
calls are made to PyDict_SetItem() and PyDict_DelItem() without checking first 
checking for PyDict_CheckExact(). 

* In PEP 372, OrderedDict was consciously specified to be a subclass of regular 
dicts in order to improve substitutability for dicts in most existing code.  
That decision had some negative consequences as well.  It is unavoidable the 
someone can call the parent class directly and undermine the invariants of the 
subclass (that is a fact of life for all subclasses that maintain their own 
state while trying to stay in-sync with state in the parent class -- see 
http://bugs.python.org/msg247358 for an example).

With pure python code for the subclass, we say, don't do that. I'll add a 
note to that effect in the docs for the OD (that said, it is a general rule 
that applies to all subclasses that have to stay synchronized to state in the 
parent).

In C version of the OD subclass, we still can't avoid being bypassed (see 
http://bugs.python.org/issue10977) and having our subclass invariants violated. 
 Though the C code can't prevent the invariants from being scrambled it does 
have an obligation to not segfault and to not leak something like 
OrderedDict([NULL]).  Ideally, if is possible to detect an invalid state 
(i.e. the linked link being out of sync with the inherited dict), then a 
RuntimeError or somesuch should be raised.

--

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



[issue24726] OrderedDict has strange behaviour when dict.__setitem__ is used.

2015-07-31 Thread Terry J. Reedy

Changes by Terry J. Reedy tjre...@udel.edu:


--
nosy: +rhettinger

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



[issue24726] OrderedDict has strange behaviour when dict.__setitem__ is used.

2015-07-26 Thread Marco Paolini

Marco Paolini added the comment:

Linking related issues http://bugs.python.org/issue24721 
http://bugs.python.org/issue24667 and http://bugs.python.org/issue24685

--
nosy: +mpaolini

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



[issue24726] OrderedDict has strange behaviour when dict.__setitem__ is used.

2015-07-26 Thread Mark Shannon

New submission from Mark Shannon:

Setting an item in an ordered dict via dict.__setitem__, or by using it as an 
object dictionary and setting an attribute on that object, creates a dictionary 
whose repr is:

OrderedDict([NULL])

Test case attached.

--
components: Library (Lib)
files: test.py
messages: 247421
nosy: Mark.Shannon, eric.snow
priority: normal
severity: normal
status: open
title: OrderedDict has strange behaviour when dict.__setitem__ is used.
type: behavior
versions: Python 3.6
Added file: http://bugs.python.org/file40028/test.py

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