[Python-ideas] anonymous object support
Nick Coghlan
ncoghlan at gmail.com
Tue Jul 26 07:50:13 CEST 2011
On Tue, Jul 26, 2011 at 2:36 PM, Matt Joiner <anacrolix at gmail.com> wrote:
> Just as a slight aside, is the special case of type() purely for convenience?
> Aren't the "new-style" ways to do this __class__ and isinstance()?
Not really - all three do different things:
1. type(x) always gives you the true metaclass of x
2. x.__class__ tells you what x claims to be (which may differ from
type(x) for things like proxy objects)
3. isinstance(x, cls) doesn't tell you what x actually *is*, just
whether or not it passes the isinstance check (it may be an instance
of a subclass, proxying for another object, or just registered if cls
refers to an ABC)
There has to be *some* way to spell number 1 and Guido chose to use
type() for it.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list