Allow an explicit owner for unbound method spies and warn if missing.
Review Request #10342 — Created Dec. 3, 2018 and submitted — Latest diff uploaded
The type and special identifying attributes for unbound methods were
removed in Python 3.x, which has proved difficult to deal with, as we're
not always able to correctly determine what the owner might be (or at
all, in the case of classes locally defined within other functions). For
those that do sort of have an owner we can look up, we won't always get
the right one, either, depending on the qualifying name of the method.We now accept passing an explicit
owner=
tospy_on()
, which will be
used for unbound methods. The owner's value is checked for
compatibility, and errors are raised if incompatible owners are provided
(with suitable messages depending on the function type and
circumstances).Failing to pass an owner will, at the very least, log a warning for the
caller to see in the event that a unit test fails, even on Python 2.x.
This is to help prepare people to transition to Python 3.x. Going
forward, we recommend always passing an owner for unbound methods.
Unit tests pass.
Used this in some new unit tests that had issues with determining
unbound method owners on Python 3.