[Python-ideas] Re: JSON encoder protocol (was Re: adding support for a "raw output" in JSON serializer)

2019-08-15 Thread Wes Turner
On Thursday, August 15, 2019, Andrew Barnert wrote: > On Aug 15, 2019, at 10:23, Christopher Barker wrote: > > > > This is all making me think it's time for a broader discussion / PEP: > > > > The future of the JSON module. > > I think this is overreacting. There’s really only two issues here, a

[Python-ideas] Re: JSON encoder protocol (was Re: adding support for a "raw output" in JSON serializer)

2019-08-15 Thread Andrew Barnert via Python-ideas
On Aug 15, 2019, at 10:23, Christopher Barker wrote: > > This is all making me think it's time for a broader discussion / PEP: > > The future of the JSON module. I think this is overreacting. There’s really only two issues here, and neither one is that major. But nobody has shown any need for

[Python-ideas] Extend ast with types for * instead of using raw lists

2019-08-15 Thread Caleb Donovick
When walking an ast it impossible to know the type of an empty list without writing down some giant lookup from node types and field names to field types. More concretely it would nice be to able to programatically visit all blocks (stmt*) without having to something like: ``` class BlockVisitor

[Python-ideas] Re: JSON encoder protocol (was Re: adding support for a "raw output" in JSON serializer)

2019-08-15 Thread Christopher Barker
This is all making me think it's time for a broader discussion / PEP: The future of the JSON module. *maybe* the way forward is to try to make a new "category killer" JSON lib (or at least a platform for standard protocols). But it also may make sense to start within Python itself -- at least for

[Python-ideas] Re: JSON encoder protocol (was Re: adding support for a "raw output" in JSON serializer)

2019-08-15 Thread Wes Turner
On Thursday, August 15, 2019, Andrew Barnert wrote: > On Aug 14, 2019, at 20:35, Wes Turner wrote: > > > A few questions then are: > > > > Should __json__() be versioned? > > Why? While there are sort of multiple versions of JSON (pre-spec, ECMA404, > and the successive RFCs), even when you know

[Python-ideas] Re: JSON encoder protocol (was Re: adding support for a "raw output" in JSON serializer)

2019-08-15 Thread Andrew Barnert via Python-ideas
On Aug 14, 2019, at 20:35, Wes Turner wrote: > A few questions then are: > > Should __json__() be versioned? Why? While there are sort of multiple versions of JSON (pre-spec, ECMA404, and the successive RFCs), even when you know which one you’re dealing with, there’s not really anything you’d

[Python-ideas] Re: adding support for a "raw output" in JSON serializer

2019-08-15 Thread Christopher Barker
> > That's one of the reasons that a simple solution of "make JSONEncoder > > respect decimal.Decimal" was rejected - I know concerns were raised, was it actually “rejected”? By whom, when? it would require that the json > > module import decimal, which is extremely costly. Is it though? I mea

[Python-ideas] Re: adding support for a "raw output" in JSON serializer

2019-08-15 Thread Dominik Vilsmeier
Steven D'Aprano wrote: > On Tue, Aug 13, 2019 at 06:01:27PM -0400, Eric V. Smith wrote: > > dataclasses does something similar: it wants to know > > if something is a > > typing.ClassVar, but it doesn't want to import typing to find out. > > Why not? Is importing typing especially expensive or a b

[Python-ideas] Re: adding support for a "raw output" in JSON serializer

2019-08-15 Thread Antoine Pitrou
On Wed, 14 Aug 2019 04:21:05 +1000 Chris Angelico wrote: > > That's one of the reasons that a simple solution of "make JSONEncoder > respect decimal.Decimal" was rejected - it would require that the json > module import decimal, which is extremely costly. Having a __json__ > protocol would be les

[Python-ideas] Re: Exception handling in objects

2019-08-15 Thread Greg Ewing
Marat Sharafutdinov wrote: try: any_module.anything except any_module.__ exception__: I'm not convinced that there are realistic use cases for this. Personally I've never been interested in catching exceptions based on which module they originated from. If there's a specific condition I wa