New GitHub issue #123431 from serhiy-storchaka:<br>
<hr>
<pre>
The C implementation of `pickle` checks (partially explicitly, partially implicitly) the type and the range of the value returned by the extension registry. These checks are redundant in normal circumstances, because it is already checked in `copyreg.add_extension()` which is the only public interface for registering an extension. It is still worth to have some checks in the C code to prevent crash, undefined behavior or producing incorrect output in improbable situation (realistically, this can happen only if you broke the extension registry).
The Python implementation does not have explicit check. Broken extension registry will cause errors (with different type and message, but this is not important), except one case -- the code with the false boolean value (`0`, `None`, `()`, etc) -- in that case it produces output. Although, there is a difference when the code has `__index__` method but is not `int`.
The following PR makes both implementations raising exception in the same circumstances (although the type of the exception may be different). The C checks are simplified. The Python check made more reliable.
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/123431">View on GitHub</a>
<p>Labels: 3.12, 3.13, 3.14</p>
<p>Assignee: </p>