mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Reimplement PySequence_Contains() and instance_contains(), so they work
safely together and don't duplicate logic (the common logic was factored out into new private API function _PySequence_IterContains()). Visible change: some_complex_number in some_instance no longer blows up if some_instance has __getitem__ but neither __contains__ nor __iter__. test_iter changed to ensure that remains true.
This commit is contained in:
parent
a8defaae04
commit
cb8d368b82
4 changed files with 67 additions and 77 deletions
|
@ -932,7 +932,17 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
|
|||
expression: o.count(value).
|
||||
*/
|
||||
|
||||
DL_IMPORT(int) PySequence_Contains(PyObject *o, PyObject *value);
|
||||
DL_IMPORT(int) PySequence_Contains(PyObject *seq, PyObject *ob);
|
||||
/*
|
||||
Return -1 if error; 1 if ob in seq; 0 if ob not in seq.
|
||||
Use __contains__ if possible, else _PySequence_IterContains().
|
||||
*/
|
||||
|
||||
DL_IMPORT(int) _PySequence_IterContains(PyObject *seq, PyObject *ob);
|
||||
/*
|
||||
Return -1 if error; 1 if ob in seq; 0 if ob not in seq.
|
||||
Always uses the iteration protocol, and only Py_EQ comparisons.
|
||||
*/
|
||||
|
||||
/* For DLL-level backwards compatibility */
|
||||
#undef PySequence_In
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue