Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ca6c84

Browse files
committed
Phase out has_key usage in the tutorial; correct docs for PyMapping_HasKey*.
1 parent fc8eef3 commit 8ca6c84

3 files changed

Lines changed: 7 additions & 10 deletions

File tree

Doc/c-api/mapping.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ Mapping Protocol
3636
.. cfunction:: int PyMapping_HasKeyString(PyObject *o, char *key)
3737

3838
On success, return ``1`` if the mapping object has the key *key* and ``0``
39-
otherwise. This is equivalent to the Python expression ``o.has_key(key)``.
40-
This function always succeeds.
39+
otherwise. This is equivalent to ``o[key]``, returning ``True`` on success
40+
and ``False`` on an exception. This function always succeeds.
4141

4242

4343
.. cfunction:: int PyMapping_HasKey(PyObject *o, PyObject *key)
4444

45-
Return ``1`` if the mapping object has the key *key* and ``0`` otherwise. This
46-
is equivalent to the Python expression ``o.has_key(key)``. This function always
47-
succeeds.
45+
Return ``1`` if the mapping object has the key *key* and ``0`` otherwise.
46+
This is equivalent to ``o[key]``, returning ``True`` on success and ``False``
47+
on an exception. This function always succeeds.
4848

4949

5050
.. cfunction:: PyObject* PyMapping_Keys(PyObject *o)

Doc/library/rfc822.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ A :class:`Message` instance has the following methods:
260260
:class:`Message` instances also support a limited mapping interface. In
261261
particular: ``m[name]`` is like ``m.getheader(name)`` but raises :exc:`KeyError`
262262
if there is no matching header; and ``len(m)``, ``m.get(name[, default])``,
263-
``m.has_key(name)``, ``m.keys()``, ``m.values()`` ``m.items()``, and
263+
``name in m``, ``m.keys()``, ``m.values()`` ``m.items()``, and
264264
``m.setdefault(name[, default])`` act as expected, with the one difference
265265
that :meth:`setdefault` uses an empty string as the default value.
266266
:class:`Message` instances also support the mapping writable interface ``m[name]

Doc/tutorial/datastructures.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,7 @@ using a non-existent key.
480480
The :meth:`keys` method of a dictionary object returns a list of all the keys
481481
used in the dictionary, in arbitrary order (if you want it sorted, just apply
482482
the :meth:`sort` method to the list of keys). To check whether a single key is
483-
in the dictionary, either use the dictionary's :meth:`has_key` method or the
484-
:keyword:`in` keyword.
483+
in the dictionary, use the :keyword:`in` keyword.
485484

486485
Here is a small example using a dictionary::
487486

@@ -497,8 +496,6 @@ Here is a small example using a dictionary::
497496
{'guido': 4127, 'irv': 4127, 'jack': 4098}
498497
>>> tel.keys()
499498
['guido', 'irv', 'jack']
500-
>>> tel.has_key('guido')
501-
True
502499
>>> 'guido' in tel
503500
True
504501

0 commit comments

Comments
 (0)