[issue19026] OrderedDict should not accept dict as parameter
Georg Brandl added the comment: Right. That's why it should not accept input that can only be unordered (including dict and **kwargs) - this is what I mean by strict mode. That's not even true: the empty and the one-element dict are always ordered. -- nosy: +georg.brandl ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19026 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19026] OrderedDict should not accept dict as parameter
New submission from anatoly techtonik: http://stackoverflow.com/questions/15733558/python-ordereddict-not-keeping-element-order I wonder why OrderedDict accepts dict as parameter in a first place? OD is used when order is important and if plain dict is supplied, the order is lost. d = {3:4, 1:2} OD(d) OrderedDict([(1, 2), (3, 4)]) OrderedDict should not accept dict as parameter. -- components: Library (Lib) messages: 197787 nosy: techtonik priority: normal severity: normal status: open title: OrderedDict should not accept dict as parameter versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19026 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19026] OrderedDict should not accept dict as parameter
Raymond Hettinger added the comment: An OrderedDict is a dict subclass and needs to accept the same inputs as dict methods. This is a guaranteed API and not a bug. It is not the OrderedDict's fault if you supply an unordered input. It can't add order after the fact. -- assignee: - rhettinger nosy: +rhettinger resolution: - rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19026 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19026] OrderedDict should not accept dict as parameter
anatoly techtonik added the comment: I don't know if it is bug or feature. There are probably cases when order is not important and OrderedDict is used, but I don't remember any. Too bad Python doesn't have first class ordered mapping type, so that it could report error if unordered arguments are supplied (such as dict or **kwargs). tag:wart -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19026 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19026] OrderedDict should not accept dict as parameter
anatoly techtonik added the comment: Is it possible to make strict OrderedDict an optional feature? Like `from features import strict_ordered_dict'? -- status: closed - pending ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19026 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19026] OrderedDict should not accept dict as parameter
Changes by Serhiy Storchaka storch...@gmail.com: -- status: pending - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19026 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19026] OrderedDict should not accept dict as parameter
Raymond Hettinger added the comment: In general, it is not possible for a hypothetical StrictOrderedDict to know whether its input was ordered or not. For the specific case of dict, it is possible, but the general case is of course completely general (i.e. if the input has a keys() method, the pairs are loaded with: for k in other.keys(): od[k] = other[k]). Those semantics are guaranteed. Remember, Armin's core concept for OrderedDict was to remember the order that keys were added, the order is determined by whoever does the adding. FWIW, the stackoverflow question was resolved trivially. The learning point is perfectly general (i.e. it explains why you write Decimal('1.1') instead of Decimal(1.1)). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19026 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19026] OrderedDict should not accept dict as parameter
anatoly techtonik added the comment: On Sun, Sep 15, 2013 at 9:25 PM, Raymond Hettinger rep...@bugs.python.org wrote: In general, it is not possible for a hypothetical StrictOrderedDict to know whether its input was ordered or not. Right. That's why it should not accept input that can only be unordered (including dict and **kwargs) - this is what I mean by strict mode. Remember, Armin's core concept for OrderedDict was to remember the order that keys were added, the order is determined by whoever does the adding. IMHO the statement the order is determined by whoever does the adding is false in 9/10 cases of passed dict. In 9/10 cases whoever supplies dict or **kwargs argument is unaware of what mistake he is making, and how many hour she will spend discovering the issue. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19026 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com