8000 bpo-41842: Add a unregister function in _codecs module by shihai1991 · Pull Request #22360 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-41842: Add a unregister function in _codecs module #22360

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 15 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
apply victor's comment
  • Loading branch information
shihai1991 committed Sep 24, 2020
commit d186726753b556ccb75646b7d6ee7235e29bc489
10 changes: 10 additions & 0 deletions Doc/c-api/codec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ Codec registry and support functions
As side effect, this tries to load the :mod:`encodings` package, if not yet
done, to make sure that it is always first in the list of search functions.

.. c:function:: int PyCodec_Unregister(PyObject *search_function)

Unregister a codec search function.

Unregister a codec search function and clear the registry's cache.
If the search function is not registered, do nothing.
Return 0 on success. Raise an exception and return -1 on success.

.. versionadded:: 3.10

.. c:function:: int PyCodec_KnownEncoding(const char *encoding)

Return ``1`` or ``0`` depending on whether there is a registered codec for
Expand Down
3 changes: 2 additions & 1 deletion Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ Base32 Encoding with Extended Hex Alphabet.
codecs
------

Add :func:`codecs.unregister` to unregister a codec search function.
Add :func:`codecs.unregister` and :c:func:`PyCodec_Unregister` to unregister
a codec search function.

curses
------
Expand Down
2 changes: 1 addition & 1 deletion Include/codecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PyAPI_FUNC(int) PyCodec_Register(

Unregister a codec search function and clear the registry's cache.
If the search function is not registered, do nothing.
*/
Return 0 on success. Raise an exception and return -1 on success. */

PyAPI_FUNC(int) PyCodec_Unregister(
PyObject *search_function
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1645,7 +1645,7 @@ def test_unregister(self):
search_function = mock.Mock(return_value=(1, 2, 3, 4))
codecs.register(search_function)
codecs.unregister(search_function)
self.assertRaises(LookupError, codecs.lookup, "test")
self.assertRaises(LookupError, codecs.lookup, "nonexistent_codec_name")
search_function.assert_not_called()

def test_lookup(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Add a :func:`codecs.unregister` to unregister a codec search function.
Add :func:`codecs.unregister` and :c:func:`PyCodec_Unregister` to unregister
a codec search function.
2 changes: 1 addition & 1 deletion Python/codecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int
PyCodec_Unregister(PyObject *search_function)
{
PyInterpreterState *interp = PyInterpreterState_Get();
/* Do nothing if codec_search_path is not created yet or was created. */
/* Do nothing if codec_search_path is not created yet or was cleared. */
if (interp->codec_search_path == NULL) {
return 0;
}
Expand Down
0