Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'badly': 0.07; 'doctest': 0.07; 'json': 0.07; 'dict': 0.09; 'output,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'repr': 0.09; 'ruby,': 0.09; 'stable.': 0.09; 'output': 0.15; 'thu,': 0.15; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:make': 0.16; 'textual': 0.16; "{'a':": 0.16; 'wrote:': 0.16; 'module,': 0.18; 'examples': 0.18; 'tests': 0.18; 'library': 0.20; 'keys': 0.22; 'subject:request': 0.22; 'pass': 0.22; 'am,': 0.23; '2015': 0.23; 'module': 0.23; "python's": 0.23; 'header:In- Reply-To:1': 0.24; 'somewhere': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'chris': 0.26; '[2]': 0.27; 'subject:/': 0.29; 'buffers': 0.29; 'such.': 0.29; 'e.g.': 0.31; 'problem': 0.33; 'equal': 0.34; 'to:addr:python-list': 0.35; 'involving': 0.35; 'protocol': 0.35; 'but': 0.36; 'text': 0.36; 'there': 0.36; 'two': 0.37; 'should': 0.37; "didn't": 0.37; 'subject:: ': 0.37; 'received:org': 0.38; 'to:addr:python.org': 0.39; 'why': 0.40; 'different': 0.64; 'charset:windows-1252': 0.65; 'ordered.': 0.84; 'subject:read': 0.84; 'subject:write': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Serhiy Storchaka Subject: Re: enhancement request: make py3 read/write py2 pickle format Date: Thu, 11 Jun 2015 14:11:25 +0300 References: <55778208$0$2899$e4fe514c@news2.news.xs4all.nl> <5577b46d$0$12975$c3e8da3$5496439d@news.astraweb.com> <5578053a$0$11102$c3e8da3@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 193.202.118.163 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1434021095 news.xs4all.nl 2903 [2001:888:2000:d::a6]:48479 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:92463 On 11.06.15 02:58, Chris Angelico wrote: > On Thu, Jun 11, 2015 at 8:10 AM, Devin Jeanpierre > wrote: >> The problem is that there are two different ways repr might write out >> a dict equal to {'a': 1, 'b': 2}. This can make tests brittle -- e.g. >> it's why doctest fails badly at examples involving dictionaries. Text >> format protocol buffers output everything sorted, so that you can do >> textual diffs for compatibility tests and such. > > With Python's JSON module [1], you can pass sort_keys=True to > stipulate that the keys be lexically ordered, which should make the > output "canonical". Pike's Standards.JSON.encode() [2] can take a flag > value to canonicalize the output, which currently has the same effect > (sort mappings by their indices). I did a quick check for Ruby and > didn't find anything in its standard library JSON module, but knowing > Ruby, it'll be available somewhere in a gem. AFAIK Ruby's dicts are ordered. So the output is pretty stable.