8000 BUG: Don't modify types after PyType_Ready by eric-wieser · Pull Request #8888 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Don't modify types after PyType_Ready #8888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions numpy/core/src/multiarray/multiarraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4367,14 +4367,14 @@ setup_scalartypes(PyObject *NPY_UNUSED(dict))
Py##child##ArrType_Type.tp_bases = \
Py_BuildValue("(OO)", &Py##parent2##ArrType_Type, \
&Py##parent1##_Type); \
Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash; \
if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \
PyErr_Print(); \
PyErr_Format(PyExc_SystemError, \
"could not initialize Py%sArrType_Type", \
#child); \
return -1; \
} \
Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;
}

/*
* In Py3K, int is no longer a fixed-width integer type, so don't
Expand Down
12 changes: 12 additions & 0 deletions numpy/core/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -2235,6 +2235,18 @@ def test_invalid_structured_dtypes(self):
a = np.ones(1, dtype=('O', [('name', 'O')]))
assert_equal(a[0], 1)

def test_correct_hash_dict(self):
# gh-8887 - __hash__ would be None despite tp_hash being set
all_types = set(np.typeDict.values()) - {np.void}
for t in all_types:
val = t()

try:
hash(val)
except TypeError as e:
assert_equal(t.__hash__, None)
else:
assert_(t.__hash__ != None)

if __name__ == "__main__":
run_module_suite()
0