Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: How to define what a class is ? Date: Wed, 24 Feb 2016 01:46:48 -0700 Lines: 23 Message-ID: References: <56cd64fb$0$9220$426a74cc@news.free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de /HxDMrl9JFgLUBsB4jHI6wybN4EnzvpJY/Qdlu/ahmbg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'override': 0.07; 'type,': 0.07; 'subject:How': 0.09; 'ast': 0.09; 'callable.': 0.09; 'subclasses': 0.09; 'wed,': 0.15; '1:08': 0.16; '2016': 0.16; '24,': 0.16; 'metaclass': 0.16; 'metaclasses': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:class': 0.16; 'wrote:': 0.16; 'all,': 0.20; 'suppose': 0.22; 'am,': 0.23; 'feb': 0.23; 'import': 0.24; 'header:In-Reply- To:1': 0.24; "doesn't": 0.26; 'define': 0.27; 'not.': 0.27; 'subject: ?': 0.27; 'message-id:@mail.gmail.com': 0.27; 'object,': 0.27; 'callable': 0.29; 'inspect': 0.29; 'subject:what': 0.29; 'raise': 0.29; 'classes': 0.30; 'class': 0.33; 'instances': 0.33; 'though.': 0.33; 'received:google.com': 0.35; 'could': 0.35; 'instance': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'received:209': 0.38; 'to:addr:python.org': 0.40; 'provide': 0.61; 'is.': 0.63; 'strictly': 0.64; '__call__': 0.84; 'to:name:python': 0.84 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=rt+M9jNJBjzJiHWunCwiROx6fY7B4wsGDvn/BGjiLQU=; b=LAlOgpUqBjoELxou6d0MNuWUWyXxrz4ObmJI3bMllhTYO9HuB63yJjpJoD+uNH7yE8 YOqhCTECgg4XUU/YSIrEFcYuOFmEnt6T1dq3ddDAlO0+Ml7d5+rdeWq8d883XGlIO7MK zsvU6jchib05jexpNT/XxlmUhmwafeGYmbbgtxqLDZY1zVxZAhBAvsPpmGTWQErfdVuu wONDPnUEgaaUB4cqET/lJySxlydZCzZvo3YYjnnySOXHlgEMWwGLY5OYZRx90YqyQi/1 e4lYU/IpzEVp2yUJMIyYLjlyT8cv1I1Xu8qN/0K2kxtQVN7pO2uYrQeAq8ze81gJ/pAW qq9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=rt+M9jNJBjzJiHWunCwiROx6fY7B4wsGDvn/BGjiLQU=; b=WMycY/G0KVxyTuGvjVvD92eS+TT7+QhRmceyZpreeID2qjrbM3ddo2dWTIxjYgnxTo an1c3Ly5Qk5EFcZZQ7rHU5kD12lI5wLNcNnvz2oMXX34oKBJeLY0NivTBT3tVMGxz/JG IK2LMyGjsvUx8l3eayw3Aa9uh8Xs9U6AobQY9ULUm5bekP28YPWDVIGE7LAD5PrXUATk QKfgv0vpKiPW5FhyC5qrP0XyIBGTVfWNNVf+mNIAsc73bN97jXddzN8ypnB4Pqpeknpc w1BwrYOrMD31jp8X8dGxzf6UBG9du0/QN10d0gxptEKjTonatgsHogte+ewv5pqGjy3U CsyQ== X-Gm-Message-State: AG10YORgd2dvqa+xVr24OWp4kfihyY+jmZ+MWEjFKkKFyxCgfxYgGH/4q5dCfM1gZT7lx0XGYqWv1ci7obfrhw== X-Received: by 10.107.185.214 with SMTP id j205mr38680967iof.111.1456303648004; Wed, 24 Feb 2016 00:47:28 -0800 (PST) In-Reply-To: <56cd64fb$0$9220$426a74cc@news.free.fr> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21rc2 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:103434 On Wed, Feb 24, 2016 at 1:08 AM, ast wrote: > Hi > > Since a class is an object, I ask myself how to define rigorously what a > class is. > > classes are instances from type, but not all, since > a class may be an instance of a metaclass All metaclasses are subclasses of type, so all classes are instances of type. > A class is always callable It doesn't strictly have to be. You could override the __call__ method in the metaclass to raise a TypeError if you don't want the class to be callable. I don't know of a use case for this, though. > Suppose I provide to you an object and that I > ask to you to tell me if it is a class or not. How > would you proceed ? import inspect inspect.isclass(x)