mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
gh-115808: Add `is_none and is_not_none to operator` (#115814)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
This commit is contained in:
parent
0fd97e46c7
commit
5580f31c56
7 changed files with 107 additions and 3 deletions
|
|
@ -728,6 +728,34 @@ _operator_is_not_impl(PyObject *module, PyObject *a, PyObject *b)
|
|||
return Py_NewRef(result);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_operator.is_none = _operator.neg
|
||||
|
||||
Same as a is None.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_operator_is_none(PyObject *module, PyObject *a)
|
||||
/*[clinic end generated code: output=07159cc102261dec input=0448b38af7b8533d]*/
|
||||
{
|
||||
PyObject *result = Py_IsNone(a) ? Py_True : Py_False;
|
||||
return Py_NewRef(result);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_operator.is_not_none = _operator.neg
|
||||
|
||||
Same as a is not None.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_operator_is_not_none(PyObject *module, PyObject *a)
|
||||
/*[clinic end generated code: output=b0168a51451d9140 input=7587f38ebac51688]*/
|
||||
{
|
||||
PyObject *result = Py_IsNone(a) ? Py_False : Py_True;
|
||||
return Py_NewRef(result);
|
||||
}
|
||||
|
||||
/* compare_digest **********************************************************/
|
||||
|
||||
/*
|
||||
|
|
@ -916,6 +944,8 @@ static struct PyMethodDef operator_methods[] = {
|
|||
_OPERATOR_COUNTOF_METHODDEF
|
||||
_OPERATOR_IS__METHODDEF
|
||||
_OPERATOR_IS_NOT_METHODDEF
|
||||
_OPERATOR_IS_NONE_METHODDEF
|
||||
_OPERATOR_IS_NOT_NONE_METHODDEF
|
||||
_OPERATOR_INDEX_METHODDEF
|
||||
_OPERATOR_ADD_METHODDEF
|
||||
_OPERATOR_SUB_METHODDEF
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue