[New-bugs-announce] [issue43509] CFunctionType object should be hashable in Python

Xinmeng Xia report at bugs.python.org
Mon Mar 15 23:10:32 EDT 2021


New submission from Xinmeng Xia <xiaxm at smail.nju.edu.cn>:

See the following examples, ctypes.resize is a built-in function and it's hashable.   ctypes.memset is a C function (CFunctionType object) and it's “unhashable”.  However,  ctypes.resize and  ctypes.memset are both immutable. They should act the same in Python. It should not report unhashable type error when ctypes.memset  calls  __hash__(). 

-----------------------------------------------
>>> import ctypes
>>> ctypes.resize
<built-in function resize>
>>> ctypes.resize.__hash__()
146309

>>> ctypes.memset
<CFunctionType object at 0x7fab55961400>
>>> ctypes.memset.__hash__()
Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
TypeError: unhashable type
-----------------------------------------------

Python version: 3.9.2
system: Ubuntu
Expected output: 
ctypes.memset is hashable.

----------
components: Interpreter Core
messages: 388804
nosy: xxm
priority: normal
severity: normal
status: open
title: CFunctionType object should be hashable in Python
type: compile error
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43509>
_______________________________________


More information about the New-bugs-announce mailing list