[Python-Dev] Re: Make HAMT available to python script

2022-04-05 Thread Christopher Barker
Thanks for the reminder Victor. For a read-only *dict*, I proposed PEP 416 "Add a frozendict builtin > type" in 2012. It was rejected. > https://peps.python.org/pep-0416/ Note that that was ten years ago -- so maybe worth revisiting. The outcome of this PEP was the addition of the types.Mapping

[Python-Dev] Re: Make HAMT available to python script

2022-04-03 Thread Victor Stinner
PEP 603 adds a frozenmap type to collections, implemented as HAMT. For a read-only *dict*, I proposed PEP 416 "Add a frozendict builtin type" in 2012. It was rejected. https://peps.python.org/pep-0416/ The outcome of this PEP was the addition of the types.MappingProxy type (previously, it already

[Python-Dev] Re: Make HAMT available to python script

2022-04-03 Thread Nick Coghlan
On Sun, 3 Apr 2022, 12:58 pm Steven D'Aprano, wrote: > > I haven't considered pickling, or deep-copying. I don't think there is > any way to get access to the underlying dict and modify it, except > perhaps via ctypes, so I think it is as immutable as it is possible to > get from Python code. Fee

[Python-Dev] Re: Make HAMT available to python script

2022-04-02 Thread Steven D'Aprano
On Sat, Apr 02, 2022 at 09:28:55AM -0700, Christopher Barker wrote: > Anyway, it would be nice for someone to take up the mantle of getting an > immutable Mapping into the stdlib. Here is a "FrozenMapping" class that could be added to collections. I have tested it ~~extensively~~ for nearly two

[Python-Dev] Re: Make HAMT available to python script

2022-04-02 Thread Christopher Barker
On Sat, Apr 2, 2022 at 6:30 AM Steve Dower wrote: > >> + 1 from me -- just the other day I was wishing it was there. > > > > There would presumably need to be be a C API as well, and that would > > probably expose more of the implementation unless handled carefully. > > Without seeing an actual i

[Python-Dev] Re: Make HAMT available to python script

2022-04-02 Thread zhang kai
> > All of that kind of adds up to make it a distraction that's likely worse > than a dict subclass with __setitem__ overridden (if that's the > behaviour you want). It's a fantastic data structure for when you need > it, but it's one that deserves to be researched and understood before > simply dr

[Python-Dev] Re: Make HAMT available to python script

2022-04-02 Thread Steve Dower
On 02Apr2022 0925, Paul Moore wrote: On Sat, 2 Apr 2022 at 02:30, Christopher Barker wrote: On Fri, Apr 1, 2022 at 4:06 AM Steve Dower wrote: The main difference is that 'immutables' offers you a stable/versioned interface to use it, while the one that's in CPython is an internal implementa

[Python-Dev] Re: Make HAMT available to python script

2022-04-02 Thread Paul Moore
On Sat, 2 Apr 2022 at 02:30, Christopher Barker wrote: > > On Fri, Apr 1, 2022 at 4:06 AM Steve Dower wrote: >> >> The main difference is that 'immutables' offers you a stable/versioned >> interface to use it, while the one that's in CPython is an internal >> implementation detail. If one day we

[Python-Dev] Re: Make HAMT available to python script

2022-04-01 Thread Christopher Barker
On Fri, Apr 1, 2022 at 4:06 AM Steve Dower wrote: > The main difference is that 'immutables' offers you a stable/versioned > interface to use it, while the one that's in CPython is an internal > implementation detail. If one day we find a better design, we can just > switch to it, while 'immutabl

[Python-Dev] Re: Make HAMT available to python script

2022-04-01 Thread zhang kai
Hi, Steve. Thanks for your detailed explanation. Indeed I already saw the API discussion in PEP 603. It's much easier to make the decision in a third-party library. I think we will be fine with the immutables library. On Fri, Apr 1, 2022 at 7:05 PM Steve Dower wrote: > On 4/1/2022 11:48 AM, zhan

[Python-Dev] Re: Make HAMT available to python script

2022-04-01 Thread Steve Dower
On 4/1/2022 11:48 AM, zhang kai wrote: Thanks Victor and Pablo. I will check the discussion of PEP 603. It's a little weird to use the immutables library when it's code in already in CPython but I'm glad it's anĀ option. The main difference is that 'immutables' offers you a stable/versioned in

[Python-Dev] Re: Make HAMT available to python script

2022-04-01 Thread zhang kai
Thanks Victor and Pablo. I will check the discussion of PEP 603. It's a little weird to use the immutables library when it's code in already in CPython but I'm glad it's an option. Kai On Fri, Apr 1, 2022 at 6:14 PM Pablo Galindo Salgado wrote: > You may want to check PEP 603, which more or les

[Python-Dev] Re: Make HAMT available to python script

2022-04-01 Thread Pablo Galindo Salgado
You may want to check PEP 603, which more or less proposes this (the author of the pep is the author of the HAMT code) check https://peps.python.org/pep-0603/ Alternatively, there is already a pypi package with this code: https://pypi.org/project/immutables/ Regards from cloudy London, Pablo O

[Python-Dev] Re: Make HAMT available to python script

2022-04-01 Thread Victor Stinner
Hi, In 2019, Yury Selivanov, who added HAMT and contextvars to Python, wrote PEP 603 "Adding a frozenmap type to collections": https://peps.python.org/pep-0603/ Sadly, the PEP was stuck in discussions: * https://discuss.python.org/t/pep-603-adding-a-frozenmap-type-to-collections/2318 * https://