◐ Shell
clean mode source ↗

bpo-16251: pickle special methods and custom __getattr__ by ambv · Pull Request #3508 · python/cpython

This PR doesn't change the lookup to types as the issue's title on BPO
suggests.  As Antoine and Raymond suggest, there'd be significant danger of
breaking existing code.

Instead, we're doing the following:

* introducing a new function in `copyreg` called `getcallable()` that mimics
`getattr()` but swallows *all* exceptions (like `hasattr()` on Python 2) and
does some basic callability tests;

* switching all relevant usage of `hasattr()` and `getattr()` in `copy` and
`copyreg` to use `getcallable()` instead.

This fixes two common failure scenarios covered at length in bpo-16251, its
duplicates, as well as on StackOverflow, etc.  Worth fixing IMHO.

Funnily enough, the recursion limit exceeded scenario happened to work on
Python 2 since `hasattr()` there swallowed the RecursionError.