Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:not': 0.03; 'definitions.': 0.07; 'defines': 0.09; 'instance.': 0.09; 'instances.': 0.09; 'subject:instance': 0.09; 'python': 0.11; 'def': 0.12; 'jan': 0.12; 'argument:': 0.16; 'callable': 0.16; 'inheritance': 0.16; 'positional': 0.16; 'rather,': 0.16; 'says...': 0.16; 'subject:)?': 0.16; 'subject:object': 0.16; 'typeerror:': 0.16; 'wrote:': 0.18; 'things.': 0.19; '>>>': 0.22; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'message- id:@mail.gmail.com': 0.30; 'class': 0.32; 'not.': 0.33; 'subject: (': 0.35; 'classes': 0.35; 'objects': 0.35; 'received:google.com': 0.35; 'instances': 0.36; 'doing': 0.36; 'method': 0.36; 'so,': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'simply': 0.61; 'here:': 0.62; 'here': 0.66; 'capable': 0.67; 'article': 0.77; '2015': 0.84; "class's": 0.84; 'whereas': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=keZmf5WghxmxdZrcM/S2g4HMdwyxXFlKklwuW9gIpNc=; b=G0Qkgth4/5oN9kNuWwfTDOpFY0yJ6ugQLXO8ECwHF7cQh3WspVZ54sWkV2TZtnto15 4OjmZ3PGNZLEBAwMLWnZMeuOy6+g3DVKGwBR6fBWqJbi1eLb+r2ocdlRlEQZ5Q2PbWRM 6Z7VA3TkYU7WdaPXOvoCkKKEbGzpv2DVNHt4GQ5fiEwvWAcS5X3pTYZ4iDmG4AMW2xWO beH98GXvmft8UY/AZzQCJvczN9suHwcMhSh9YgMgVBri1wWrfCVD38ItPMEQHRHtemnk fuKOtqNPR4Sr6fZixksQX3uSnNkp1oiLidf10CeMyjbU71vAJ3ilmLo7Nn1AqULTr6zK pLXw== X-Received: by 10.68.129.39 with SMTP id nt7mr1771810pbb.96.1422411398111; Tue, 27 Jan 2015 18:16:38 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Tue, 27 Jan 2015 19:15:57 -0700 Subject: Re: An object is an instance (or not)? To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1422411406 news.xs4all.nl 2865 [2001:888:2000:d::a6]:57138 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:84707 On Tue, Jan 27, 2015 at 5:17 PM, Mario Figueiredo wrote: > In article , > ned@nedbatchelder.com says... >> What does "participate in OOP" mean? > > Means the object is capable of participating in inheritance and/or > polymorphism. An instance of an object is capable of doing so, per its > class definitions. Whereas a Python class object is not. Python class objects are capable of doing both these things. > >>> class Master: > def func(self): > pass > > >>> class Sub(Master): > pass > > >>> Sub.func() > TypeError: func() missing 1 required positional argument: 'self' You get the same result by calling Master.func(), so I don't see how this is a counter-example. Anyway, here is how class objects participate in inheritance: class BaseMetaClass(type): def func(cls): return 42 class DerivedMetaClass(BaseMetaClass): pass class DerivedClass(metaclass=DerivedMetaClass): pass >>> isinstance(DerivedClass, BaseMetaClass) True >>> print(DerivedClass.func()) 42 Note that this is exactly the same way that non-class objects participate in inheritance. Instances don't simply inherit from other instances. Rather, the class of the instance inherits from other classes and provides methods to the instances. And that's what happens here: the class's meta class inherits from another, and the method it defines is callable on the instance.