Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #77535

Re: Storing instances using jsonpickle

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
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; 'python.': 0.02; 'syntax': 0.04; 'classes,': 0.05; 'encoding': 0.05; 'mrab': 0.05; 'output': 0.05; 'say,': 0.05; '(so': 0.07; 'encoded': 0.07; 'json': 0.07; '[0,': 0.09; 'arguments': 0.09; 'delimited': 0.09; 'encode': 0.09; 'encoder': 0.09; 'here?': 0.09; 'occasionally': 0.09; 'subject:using': 0.09; 'subset': 0.09; 'subtle': 0.09; 'trailing': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; "wouldn't": 0.14; '(0,': 0.16; '2):': 0.16; ':-(': 0.16; 'advocating': 0.16; 'ah,': 0.16; 'arguments:': 0.16; 'bracket': 0.16; 'brackets': 0.16; 'called,': 0.16; 'comma': 0.16; 'comma,': 0.16; 'comma.': 0.16; 'delimiter': 0.16; 'dict': 0.16; 'fine.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'interpreter,': 0.16; 'it),': 0.16; 'json,': 0.16; 'notation': 0.16; 'one-element': 0.16; 'parentheses': 0.16; 'parentheses:': 0.16; 'pity': 0.16; 'plop': 0.16; 'positional': 0.16; 'repl': 0.16; 'set:': 0.16; 'superfluous': 0.16; 'syntax,': 0.16; 'tremendous': 0.16; 'tuple': 0.16; 'tuple,': 0.16; 'tuple.': 0.16; 'tuples,': 0.16; 'typos': 0.16; '(0)': 0.16; 'followed': 0.16; 'prevent': 0.16; 'wrote:': 0.18; '(not': 0.18; 'passing': 0.19; 'thu,': 0.19; 'seems': 0.21; 'cc:addr:python.org': 0.22; "aren't": 0.24; 'issue,': 0.24; 'parse': 0.24; '(or': 0.24; 'cc:2**0': 0.24; 'equivalent': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; "doesn't": 0.30; 'sets': 0.30; 'start,': 0.30; 'strongly': 0.30; 'message-id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; "i'm": 0.30; 'went': 0.31; 'that.': 0.31; 'convenience': 0.31; 'correctly.': 0.31; 'int,': 0.31; 'object.': 0.31; 'sep': 0.31; 'sets.': 0.31; "they'll": 0.31; 'tuples': 0.31; 'types.': 0.31; 'there,': 0.34; "i'd": 0.34; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'format.': 0.36; 'keyword': 0.36; 'example,': 0.37; 'handle': 0.38; 'whatever': 0.38; 'though,': 0.39; 'even': 0.60; 'problems.': 0.60; 'name:': 0.61; 'making': 0.63; 'name': 0.63; 'more': 0.64; 'different': 0.65; 'worth': 0.66; 'between': 0.67; 'default': 0.69; 'hoping': 0.75; 'calm': 0.84; "class's": 0.84; 'collision': 0.84; 'confusion.': 0.84; 'float,': 0.84; "it'd": 0.84; 'pike': 0.84; 'afford': 0.91; 'good,': 0.91; 'yes!': 0.91; 'to:none': 0.92; 'anywhere,': 0.93; 'suited': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=fJjS+0P0pOMdT3nFWVyAbwEQHBzpf2V0zaM13MkOwzU=; b=a8wM4aey9qt+Gsl0rqZKuzoo4/cKP4U7ctaKVeNvkzFbqgWbbhCnKAL5WxHAFgI+/+ 1O9DP/qwCk3r69MnVR2RyFQEtbX3KrJk71UhuwccCqA8B1hH0K8u8j62/r9XoyqWHZcH gQMdcvPEJENJef/ehH4nY30mkWA3WBcPmvE7QwcgpxPlWnCKSEFqz3eRiZ2w3nefMIYc FbGv1k78NiXiqfb2SNsDnxBx8j1qhzkL8hVGUO9oY76gHNJgmTbtjYftAHvFvDXo2oMf nPent3bVkOQqYA8+DzPiaWj861/bl8SKq97tD50/9y7u9+/VsAHSAE3dpKS0Z/jPhkhY dVXw==
MIME-Version 1.0
X-Received by 10.42.118.211 with SMTP id y19mr2356838icq.12.1409807837576; Wed, 03 Sep 2014 22:17:17 -0700 (PDT)
In-Reply-To <5407A69B.3030707@mrabarnett.plus.com>
References <c54f7a2f-cf2c-4ee9-ba8e-a309761c1c6a@googlegroups.com> <mailman.13748.1409777587.18130.python-list@python.org> <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> <5407A69B.3030707@mrabarnett.plus.com>
Date Thu, 4 Sep 2014 15:17:17 +1000
Subject Re: Storing instances using jsonpickle
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.13761.1409807846.18130.python-list@python.org> (permalink)
Lines 96
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1409807846 news.xs4all.nl 2857 [2001:888:2000:d::a6]:41549
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:77535

Show key headers only | View raw


On Thu, Sep 4, 2014 at 9:39 AM, MRAB <python@mrabarnett.plus.com> wrote:
> I occasionally think about a superset of JSON, called, say, "pyson" ...
> ah, name already taken! :-(

While I'm somewhat sympathetic to the concept, there are some parts of
your description that I disagree with. Am I misreading something? Are
there typos in the description and I'm making something out of
nothing?

> It would add tuples, delimited by (...), which are not used otherwise (no
> expressions):
>
>     () => ()
>     (0, ) => (0)

This seems odd. Part of JSON's convenience is that it's a subset of
JavaScript syntax, so you can just plop a block of JSON into a REPL
and it'll decode correctly. With PyON (or whatever you call it), it'd
be nice to have the same correspondence; for a start, I would strongly
encourage the "trailing comma is permitted" rule (so [1,2,3,] is
equivalent to [1,2,3]), and then I'd have the default encoding for a
single-element tuple include that trailing comma. If (0) is a
one-element tuple, you end up with a subtle difference between a PyON
decode and the Python interpreter, which is likely to cause problems.
It might even be worth actually mandating (not just encouraging) that
one-element tuples have the trailing comma, just to prevent that.

> The key of a dict could also be int, float, or tuple.

Yes! Yes! DEFINITELY do this!! Ahem. Calm down a little, it's not that
outlandish an idea...

> It could support other classes, and could handle named arguments.
>
> For example, sets:
>
> To encode {0, 1, 2):

Do you mean {0, 1, 2} here? I'm hoping you aren't advocating a syntax
that mismatches bracket types. That's only going to cause confusion.

>     Look in encoder dict for encoder function with class's name ('set') and
> call it, passing object.
>
>     Encoder returns positional and keyword arguments: [0, 1, 2] and {}.
>
>     Output name, followed by encoded arguments in parentheses.
>
>     Encoder for set:
>
>     def encode_set(obj):
>         return list(obj), {}
>
> To decode 'set(0, 1, 2)':
>
>     Parse name: 'set'.
>
>     Parse contents of parentheses: [0, 1, 2] and {}.
>
>     Look in decoder dict for decoder function with given name ('set') and
> call it, passing arguments.
>
>     Result would be {0, 1, 2}.
>
>     Decoder for set:
>
>     def decode_set(*args):
>         return set(args)
>
> pyson.dumps({0, 1, 2}, decoders={'set': decode_set}) would return 'set(0, 1,
> 2)'.
>
> pyson.loads('set(0, 1, 2)', encoders={'set': encode_set}) would return {0,
> 1, 2}.

This seems very much overengineered. Keep it much more simple; adding
set notation is well and good, but keyword arguments aren't necessary
there, and I'm not seeing a tremendous use-case for them.

It's a pity Python has the collision of sets and dicts both using
braces. Pike went for two-character delimiters, which might be better
suited here; round brackets aren't used in JSON anywhere, so you can
afford to steal them:

{'this':'is', 'a':'dict'}
({'this','is','a','set'})

Empty sets would be an issue, though, as they'll be different in
Python and this format. But everything else would work fine. You have
a two-character delimiter in PyON, and superfluous parentheses around
set notation in Python.

(Sadly, this doesn't make it Pike-compatible, as Pike uses (<x,y,z>)
for sets. But it wouldn't have been anyway.)

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Storing instances using jsonpickle Josh English <Joshua.R.English@gmail.com> - 2014-09-03 13:32 -0700
  Re: Storing instances using jsonpickle Ned Batchelder <ned@nedbatchelder.com> - 2014-09-03 16:52 -0400
    Re: Storing instances using jsonpickle Josh English <Joshua.R.English@gmail.com> - 2014-09-03 15:30 -0700
      Re: Storing instances using jsonpickle MRAB <python@mrabarnett.plus.com> - 2014-09-04 00:39 +0100
        Re: Storing instances using jsonpickle Denis McMahon <denismfmcmahon@gmail.com> - 2014-09-04 01:11 +0000
      Re: Storing instances using jsonpickle Ned Batchelder <ned@nedbatchelder.com> - 2014-09-03 22:18 -0400
        Re: Storing instances using jsonpickle Sam Raker <sam.raker@gmail.com> - 2014-09-03 21:52 -0700
        Re: Storing instances using jsonpickle Josh English <Joshua.R.English@gmail.com> - 2014-09-15 12:30 -0700
      Re: Storing instances using jsonpickle Chris Angelico <rosuav@gmail.com> - 2014-09-04 15:17 +1000
        Re: Storing instances using jsonpickle Dan Sommers <dan@tombstonezero.net> - 2014-09-05 04:38 +0000
          Re: Storing instances using jsonpickle Chris Angelico <rosuav@gmail.com> - 2014-09-05 15:08 +1000
      Re: Storing instances using jsonpickle MRAB <python@mrabarnett.plus.com> - 2014-09-04 12:07 +0100
      Re: Storing instances using jsonpickle MRAB <python@mrabarnett.plus.com> - 2014-09-05 18:04 +0100
        Re: Storing instances using jsonpickle Marko Rauhamaa <marko@pacujo.net> - 2014-09-05 20:16 +0300
          Re: Storing instances using jsonpickle Ned Batchelder <ned@nedbatchelder.com> - 2014-09-05 13:30 -0400
            Re: Storing instances using jsonpickle Marko Rauhamaa <marko@pacujo.net> - 2014-09-05 21:04 +0300
              Re: Storing instances using jsonpickle Ned Batchelder <ned@nedbatchelder.com> - 2014-09-05 16:50 -0400
                Re: Storing instances using jsonpickle Marko Rauhamaa <marko@pacujo.net> - 2014-09-05 23:57 +0300
          Re: Storing instances using jsonpickle Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2014-09-06 00:18 +0200
      Re: Storing instances using jsonpickle Chris Angelico <rosuav@gmail.com> - 2014-09-06 10:20 +1000
      Re: Storing instances using jsonpickle MRAB <python@mrabarnett.plus.com> - 2014-09-06 17:32 +0100
      Re: Storing instances using jsonpickle Ned Batchelder <ned@nedbatchelder.com> - 2014-09-06 12:56 -0400
      Re: Storing instances using jsonpickle Terry Reedy <tjreedy@udel.edu> - 2014-09-06 14:27 -0400

csiph-web