[Python-ideas] Re: set arbitrary hash random seed to ensure reproducible results

2021-12-23 Thread Chris Angelico
On Fri, Dec 24, 2021 at 12:14 AM Hao Hu wrote: >- generalize the signature of __hash__(object) to __hash__(object, > *args, **kwargs). In the default implementation, we discard the keyword > "salt" and use the default fallback salt if the keyword is not present, > otherwise we use the salt spe

[Python-ideas] Re: set arbitrary hash random seed to ensure reproducible results

2021-12-23 Thread Hao Hu
On 12/23/21 07:39, Stephen J. Turnbull wrote: Hao Hu writes: > On 12/18/21 08:44, Stephen J. Turnbull wrote: > > Hao Hu writes: > > > >> For instance, if we create a caching programming interface that > > > >> relies on a distributed kv store, > > > > I would be very suspicious

[Python-ideas] Re: set arbitrary hash random seed to ensure reproducible results

2021-12-22 Thread Chris Angelico
On Thu, Dec 23, 2021 at 5:40 PM Stephen J. Turnbull wrote: > > Hao Hu writes: > > On 12/18/21 08:44, Stephen J. Turnbull wrote: > > > Hao Hu writes: > > > > > >> For instance, if we create a caching programming interface that > > > > >> relies on a distributed kv store, > > > > > > I wou

[Python-ideas] Re: set arbitrary hash random seed to ensure reproducible results

2021-12-22 Thread Stephen J. Turnbull
Hao Hu writes: > On 12/18/21 08:44, Stephen J. Turnbull wrote: > > Hao Hu writes: > > > >> For instance, if we create a caching programming interface that > > > >> relies on a distributed kv store, > > > > I would be very suspicious of using Python's hash builtin for such a > > purpose.

[Python-ideas] Re: set arbitrary hash random seed to ensure reproducible results

2021-12-18 Thread Hao Hu
On 12/18/21 08:44, Stephen J. Turnbull wrote: Hao Hu writes: > > On 17 Dec 2021, at 15:28, Chris Angelico wrote: > > The built-in hash() function is extremely generic, so it can't really > > work that way. Adding a parameter to it would require (a) adding the > > parameter to every __h

[Python-ideas] Re: set arbitrary hash random seed to ensure reproducible results

2021-12-17 Thread Stephen J. Turnbull
Hao Hu writes: > > On 17 Dec 2021, at 15:28, Chris Angelico wrote: > > The built-in hash() function is extremely generic, so it can't really > > work that way. Adding a parameter to it would require (a) adding the > > parameter to every __hash__ method of every object, including > > user-def

[Python-ideas] Re: set arbitrary hash random seed to ensure reproducible results

2021-12-17 Thread Hao Hu
> On 17 Dec 2021, at 15:49, Chris Angelico wrote: > > On Sat, Dec 18, 2021 at 1:44 AM Hao Hu wrote: >>> For that sort of thing, it may be more practical to use your own >>> hashing function, possibly a cryptographically secure one. The precise >>> hashing function used by Python isn't guarante

[Python-ideas] Re: set arbitrary hash random seed to ensure reproducible results

2021-12-17 Thread Chris Angelico
On Sat, Dec 18, 2021 at 2:21 AM Hao Hu wrote: > Great question. I agree that there could be other factors which slow things > down much more than the hash function. > I assume that this is a function that’ll be potentially called a lot of > times, and the cumulated cost won’t be negligible. > Ma

[Python-ideas] Re: set arbitrary hash random seed to ensure reproducible results

2021-12-17 Thread Hao Hu
> On 17 Dec 2021, at 15:42, Steven D'Aprano wrote: > > On Fri, Dec 17, 2021 at 02:07:38PM -, Hao Hu wrote: >> Hi, >> >> I am wondering if it would be good to add an additional keyword `seed` >> to the builtin function *hash* to allow us to set arbitrary seed to >> ensure reproducible re

[Python-ideas] Re: set arbitrary hash random seed to ensure reproducible results

2021-12-17 Thread Chris Angelico
On Sat, Dec 18, 2021 at 1:44 AM Hao Hu wrote: > > For that sort of thing, it may be more practical to use your own > > hashing function, possibly a cryptographically secure one. The precise > > hashing function used by Python isn't guaranteed, so if you need it to > > be stable across different ru

[Python-ideas] Re: set arbitrary hash random seed to ensure reproducible results

2021-12-17 Thread Steven D'Aprano
On Fri, Dec 17, 2021 at 02:07:38PM -, Hao Hu wrote: > Hi, > > I am wondering if it would be good to add an additional keyword `seed` > to the builtin function *hash* to allow us to set arbitrary seed to > ensure reproducible results. I assume you are talking about hashing strings, I believe

[Python-ideas] Re: set arbitrary hash random seed to ensure reproducible results

2021-12-17 Thread Hao Hu
> On 17 Dec 2021, at 15:28, Chris Angelico wrote: > > On Sat, Dec 18, 2021 at 1:21 AM Hao Hu wrote: >> >> Hi, >> >> I am wondering if it would be good to add an additional keyword `seed` to >> the builtin function *hash* to allow us to set arbitrary seed to ensure >> reproducible results. >

[Python-ideas] Re: set arbitrary hash random seed to ensure reproducible results

2021-12-17 Thread Chris Angelico
On Sat, Dec 18, 2021 at 1:21 AM Hao Hu wrote: > > Hi, > > I am wondering if it would be good to add an additional keyword `seed` to the > builtin function *hash* to allow us to set arbitrary seed to ensure > reproducible results. > The built-in hash() function is extremely generic, so it can't