bpo-16251: pickle special methods and custom getattr by ambv · Pull Request #3508 · python/cpython (original) (raw)
This PR doesn't change the lookup to types as the issue's title on BPO
suggests. As Antoine and Raymond point out, there'd be significant danger of
breaking existing code.
Instead, we're doing the following:
- introducing a new function in
copyreg
calledgetcallable()
that mimicsgetattr()
but swallows all exceptions (likehasattr()
on Python 2) and
does some basic callability tests; - switching all relevant usage of
hasattr()
andgetattr()
incopy
andcopyreg
to usegetcallable()
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.