Re: How to implement freelists in dict 3.10 for previous versions?

2021-12-29 Thread Inada Naoki
On Wed, Dec 29, 2021 at 7:25 PM Marco Sulla wrote: > > I noticed that now freelists in dict use _Py_dict_state. I suppose > this is done for thread safety. > Some core-dev are working on per-interpreter GIL. But it is not done yet. So you don't need to follow it soon. Your extension module will w

Re: recover pickled data: pickle data was truncated

2021-12-29 Thread Marco Sulla
On Wed, 29 Dec 2021 at 18:33, iMath wrote: > But I found the size of the file of the shelve data didn't change much, so I > guess the data are still in it , I just wonder any way to recover my data. I agree with Barry, Chris and Avi. IMHO your data is lost. Unpickling it by hand is a harsh work

RE: recover pickled data: pickle data was truncated

2021-12-29 Thread Avi Gross via Python-list
I am not an expert on the topic but my first reaction is it depends on how the data is corrupted and we do not know that. So I am addressing a more general concept here. Some algorithms break if a single byte or even bit changes and nothing beyond that point makes sense. Many encryption techniques

Re: recover pickled data: pickle data was truncated

2021-12-29 Thread Chris Angelico
On Thu, Dec 30, 2021 at 4:32 AM iMath wrote: > > > You have lost the data in that case. > > But I found the size of the file of the shelve data didn't change much, so I > guess the data are still in it , I just wonder any way to recover my data. Unless two conflicting versions got interleaved, i

Re: recover pickled data: pickle data was truncated

2021-12-29 Thread iMath
> You have lost the data in that case. But I found the size of the file of the shelve data didn't change much, so I guess the data are still in it , I just wonder any way to recover my data. -- https://mail.python.org/mailman/listinfo/python-list

Re: What's the public API alternative to _PyObject_GC_IS_TRACKED()?

2021-12-29 Thread Marco Sulla
On Wed, 29 Dec 2021 at 12:11, Dieter Maurer wrote: > > Marco Sulla wrote at 2021-12-29 11:59 +0100: > >On Wed, 29 Dec 2021 at 09:12, Dieter Maurer wrote: > >> `MutableMapping` is a so called abstract base class (--> `abc`). > >> > >> It uses the `__subclass_check__` (and `__instance_check__`) of

Re: What's the public API alternative to _PyObject_GC_IS_TRACKED()?

2021-12-29 Thread Dieter Maurer
Marco Sulla wrote at 2021-12-29 11:59 +0100: >On Wed, 29 Dec 2021 at 09:12, Dieter Maurer wrote: >> `MutableMapping` is a so called abstract base class (--> `abc`). >> >> It uses the `__subclass_check__` (and `__instance_check__`) of >> `abc.ABCMeta` to ensure `issubclass(dict, MutableMapping)`. >

Re: What's the public API alternative to _PyObject_GC_IS_TRACKED()?

2021-12-29 Thread Marco Sulla
On Wed, 29 Dec 2021 at 09:12, Dieter Maurer wrote: > `MutableMapping` is a so called abstract base class (--> `abc`). > > It uses the `__subclass_check__` (and `__instance_check__`) of > `abc.ABCMeta` to ensure `issubclass(dict, MutableMapping)`. > Those can be customized by overriding `MutableMap

How to implement freelists in dict 3.10 for previous versions?

2021-12-29 Thread Marco Sulla
I noticed that now freelists in dict use _Py_dict_state. I suppose this is done for thread safety. I would implement it also for a C extension that uses CPython < 3.10. How can I achieve this? -- https://mail.python.org/mailman/listinfo/python-list

Re: What's the public API alternative to _PyObject_GC_IS_TRACKED()?

2021-12-29 Thread Marco Sulla
On Wed, 29 Dec 2021 at 10:06, Dieter Maurer wrote: > > Are you sure you need to implement your type in C at all? It's already implemented, and, in some cases, is faster than dict: https://github.com/Marco-Sulla/python-frozendict#benchmarks PS: I'm doing a refactoring that speeds up creation eve

Re: What's the public API alternative to _PyObject_GC_IS_TRACKED()?

2021-12-29 Thread Chris Angelico
On Wed, Dec 29, 2021 at 8:07 PM Dieter Maurer wrote: > > Marco Sulla wrote at 2021-12-29 09:29 +0100: > >On second thought, I think I'll do this for the pure py version. But I > >will definitely not do this for the C extension > > Are you sure you need to implement your type in C at all? > > I mad

Re: What's the public API alternative to _PyObject_GC_IS_TRACKED()?

2021-12-29 Thread Dieter Maurer
Marco Sulla wrote at 2021-12-29 09:29 +0100: >On second thought, I think I'll do this for the pure py version. But I >will definitely not do this for the C extension Are you sure you need to implement your type in C at all? I made a small `timeit` test: ``` >>> class cd(dict): pass ... >>> timeit

Re: What's the public API alternative to _PyObject_GC_IS_TRACKED()?

2021-12-29 Thread Marco Sulla
On second thought, I think I'll do this for the pure py version. But I will definitely not do this for the C extension, since it's anyway strange that an immutable mapping inherits from a mutable one! I've done it in the pure py version only for a matter of speed. On Wed, 29 Dec 2021 at 09:24, Mar

Re: What's the public API alternative to _PyObject_GC_IS_TRACKED()?

2021-12-29 Thread Marco Sulla
On Wed, 29 Dec 2021 at 09:12, Dieter Maurer wrote: > > Marco Sulla wrote at 2021-12-29 08:08 +0100: > >On Wed, 29 Dec 2021 at 00:03, Dieter Maurer wrote: > >> Why do you not derive from `dict` and override its mutating methods > >> (to raise a type error after initialization is complete)? > > > >

Re: Option for venv to upgrade pip automatically?

2021-12-29 Thread Marco Sulla
Cool, thanks! On Wed, 29 Dec 2021 at 07:10, Inada Naoki wrote: > > You can use --upgrade-deps option. My alias is: > > alias mkvenv='python3 -m venv --upgrade-deps --prompt . venv' > > On Wed, Dec 29, 2021 at 4:55 AM Marco Sulla > wrote: > > > > I think it's very boring that, after creating a

Re: What's the public API alternative to _PyObject_GC_IS_TRACKED()?

2021-12-29 Thread Dieter Maurer
Marco Sulla wrote at 2021-12-29 08:08 +0100: >On Wed, 29 Dec 2021 at 00:03, Dieter Maurer wrote: >> Why do you not derive from `dict` and override its mutating methods >> (to raise a type error after initialization is complete)? > >I've done this for the pure py version, for speed. But in this way