[issue29200] is it a bug in `functools._HashedSeq`

2017-01-08 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
stage:  -> resolved

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29200] is it a bug in `functools._HashedSeq`

2017-01-07 Thread Jiajun Huang

Jiajun Huang added the comment:

thanks for reply :)

2017年1月8日星期日,Roundup Robot  写道:

>
> Roundup Robot added the comment:
>
> New changeset 2e7e91785306 by Raymond Hettinger in branch 'default':
> Issue #29200: Fix test to use self.assertEqual instead of py.test style
> tests
> https://hg.python.org/cpython/rev/2e7e91785306
>
> --
>
> ___
> Python tracker >
> 
> ___
>

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29200] is it a bug in `functools._HashedSeq`

2017-01-07 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 2e7e91785306 by Raymond Hettinger in branch 'default':
Issue #29200: Fix test to use self.assertEqual instead of py.test style tests
https://hg.python.org/cpython/rev/2e7e91785306

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29200] is it a bug in `functools._HashedSeq`

2017-01-07 Thread Raymond Hettinger

Raymond Hettinger added the comment:

To honor your report, I've added a test for this functionality.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29200] is it a bug in `functools._HashedSeq`

2017-01-07 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 52d3cbcf546f by Raymond Hettinger in branch 'default':
Issue #29200: Add test for lru cache only calling __hash__ once
https://hg.python.org/cpython/rev/52d3cbcf546f

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29200] is it a bug in `functools._HashedSeq`

2017-01-07 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Sorry, but I think you've missed the point of _HashedSeq.  The hash() is called 
no more than once per instance, not once per instance creation.

>>> from functools import _HashedSeq
>>> from unittest.mock import Mock
>>> test_tup = 1, 2, 3, "hello", "world"
>>> hash_func = Mock(return_value=999)
>>> hs = _HashedSeq(test_tup, hash=hash_func)
>>> hash(hs)
999
>>> hash(hs)
999
>>> hash(hs)
999
>>> hash_func.call_count
1

--
resolution:  -> not a bug
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29200] is it a bug in `functools._HashedSeq`

2017-01-07 Thread Raymond Hettinger

Changes by Raymond Hettinger :


--
assignee:  -> rhettinger
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29200] is it a bug in `functools._HashedSeq`

2017-01-07 Thread Jiajun Huang

New submission from Jiajun Huang:

the class definition:

class _HashedSeq(list):
""" This class guarantees that hash() will be called no more than once
per element.  This is important because the lru_cache() will hash
the key multiple times on a cache miss.

"""

__slots__ = 'hashvalue'

def __init__(self, tup, hash=hash):
self[:] = tup
self.hashvalue = hash(tup)

def __hash__(self):
return self.hashvalue

and I've test for it:

In [1]: from functools import _HashedSeq

In [2]: from unittest.mock import Mock

In [3]: test_tup = 1, 2, 3, "hello", "world"

In [4]: hash_func = Mock()

In [5]: _HashedSeq(test_tup, hash=hash_func)
Out[5]: [1, 2, 3, 'hello', 'world']

In [6]: _HashedSeq(test_tup, hash=hash_func)
Out[6]: [1, 2, 3, 'hello', 'world']

In [7]: _HashedSeq(test_tup, hash=hash_func)
Out[7]: [1, 2, 3, 'hello', 'world']

In [8]: hash_func.call_count
Out[8]: 3

the hash function had been called 3 times rather than 1.

--
components: Library (Lib)
messages: 284949
nosy: Jiajun Huang
priority: normal
severity: normal
status: open
title: is it a bug in `functools._HashedSeq`
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com