osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

proposal for slice hashing


On 5/11/2020 3:58 PM, Will Bradshaw wrote:
> I recently ran into a situation where I needed to hash a slice and found this to be unsupported. 

Slice objects, as opposed to slices of objects, have no explicit use in 
Python itself.  They were added for use by "NumericalPython and other 
3rd party extensions".
https://docs.python.org/3/library/functions.html#slice
They have the functionality needed for that use.  If this does not meet 
your needs, don't use them.

Slice objects are similar to named tuples in having a fixed number of 
immutable fields accessed by name.
https://docs.python.org/3/glossary.html#term-named-tuple
They were added before collections.namedtuple but if added today *for 
general use*, probably would be nametuples, with hashing and anything 
that comes from subclassing tuple.

So either use the namedtuple factory or roll your own to make something 
that works for you.


-- 
Terry Jan Reedy