[Python-Dev] Python 3, new-style classes and class (original) (raw)

Vinay Sajip vinay_sajip at yahoo.co.uk
Sun Nov 20 00:11:38 CET 2011


Michael Foord <fuzzyman voidspace.org.uk> writes:

That works fine in Python 3 (mock.Mock does it):

>>> class Foo(object): ... @property ... def class(self): ... return int ... >>> a = Foo() >>> isinstance(a, int) True >>> a.class <class 'int'> There must be something else going on here.

Michael, thanks for the quick response. Okay, I'll dig in a bit further: the definition in SimpleLazyObject is

class = property(new_method_proxy(operator.attrgetter("class")))

so perhaps the problem is something related to the specifics of the definition. Here's what I found in initial exploration:


In Python 3, there's no class property as there is in Python 2, the fake_bool's type isn't bool, and the callable to set up the wrapped object never gets called (which is why _wrapped is not set to True, but to an anonymous object - this is set in SimpleLazyObject.init).

Puzzling!

Regards,

Vinay Sajip



More information about the Python-Dev mailing list