Upgrade to release 2.3.0:
- The __trunc__(), __floor__() and __ceil__() special methods are
now implemented by object proxies, delegating to math.trunc(),
math.floor() and math.ceil() applied to the wrapped object. As
with other special methods, these are only looked up on the class
type and not the instance, so they cannot rely on the __getattr__()
fallback of the proxy and must be implemented explicitly. Previously
calling math.trunc() on an object proxy raised TypeError. These
special methods sit somewhat outside the core Python object model
in that they are not used by any builtin operators, with the math
module being their only consumer. They are however documented as
part of the Python data model and the math module is a key module
in the standard library, so supporting them is warranted, in the
same way as the existing support for __round__(), which is
consumed by the round() builtin. Note that although math.floor()
and math.ceil() previously appeared to work when used on an object
proxy, they were silently falling back to converting the proxy
using __float__(). If the wrapped object provided its own
__floor__() or __ceil__() special methods these were ignored and
the result could differ from that when the wrapped object was
used directly. These now yield the same result as using the
wrapped object directly. With thanks to Vincent Gao for the PR.
- The __fspath__() special method of the os.PathLike protocol has
been added to the set of dunder methods which AutoObjectProxy
detects on the wrapped object and adds to the class it
generates, so a proxy it creates around a path-like object can
now be used with os.fspath(), the builtin open() and other
standard library functions accepting paths. Note that
__fspath__() is deliberately not implemented by the base
object proxy, since its presence on the proxy type would
cause every proxy to be classified as path-like by code
branching on isinstance(obj, os.PathLike). Also be aware
that AutoObjectProxy creates a new class for every proxy
instance, so it should not be used to wrap path-like
objects in large numbers due to the memory overhead. For
high-frequency use define a custom proxy class which adds an
explicit __fspath__() method instead. See the section on
wrapping path-like objects in the known issues documentation
for more details.
Signed-off-by: Leon Anavi <leon.anavi@konsulko.com>
Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>