Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103492
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | eryk sun <eryksun@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: How to define what a class is ? |
| Date | Thu, 25 Feb 2016 05:21:43 -0600 |
| Lines | 34 |
| Message-ID | <mailman.121.1456399345.20994.python-list@python.org> (permalink) |
| References | <56cd64fb$0$9220$426a74cc@news.free.fr> <mailman.85.1456303651.20994.python-list@python.org> <56cecf47$0$3305$426a74cc@news.free.fr> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de Zs0czgeaIIiggg3TBC0Dkw8Y6gQz+kg8IZ1QDtANmq3A== |
| Return-Path | <eryksun@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'classes,': 0.05; 'subject:How': 0.09; '"""return': 0.09; 'ast': 0.09; 'subclass': 0.09; 'type)': 0.09; 'python': 0.10; 'def': 0.13; 'thu,': 0.15; '2016': 0.16; 'attributes:': 0.16; 'new-style': 0.16; 'old-style': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:class': 0.16; 'wrote:': 0.16; 'string': 0.17; '>>>': 0.20; 'cc:2**0': 0.20; '2.x': 0.22; "aren't": 0.22; 'pass': 0.22; 'am,': 0.23; 'feb': 0.23; 'header :In-Reply-To:1': 0.24; 'module': 0.25; 'equivalent': 0.27; 'subject: ?': 0.27; 'message-id:@mail.gmail.com': 0.27; 'subject:what': 0.29; 'objects': 0.29; 'classes': 0.30; 'code': 0.30; 'class.': 0.30; 'class': 0.33; 'source': 0.33; 'instances': 0.33; 'lets': 0.33; 'except': 0.34; 'received:google.com': 0.35; 'instance': 0.35; 'instead': 0.36; 'received:209.85': 0.36; '(i.e.': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'to:addr:python.org': 0.40; 'provide': 0.61; 'conclude': 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 :cc; bh=O78FZW+g790v1jNRDp1zMf0jkM8UlWCu4fYCipwCd6Y=; b=pfmLz+EXdXA8tXRiZVIGC1EuEMlQ45Y92gRmSYLWBmQRzSiZ6cnGNHQ21iQ90v5OBN mm1Dczy7Ub8ak/8Pwj6kx22Pc8alpFl9GTN90Z8mSXcNj7U0NnIq6cxZPOzqHkWm/XYR Za96cHF7vxFnUUKb3dpk9dogycU33A3kJm6wPZESdnf99mR5ovjIMt21mIFDp7Uc2QnL plmAgU/xLFhAJ2klHbnAij9MsBMgjQ3FnHoz31v4R/SlXCgxUcEncS0FjvfR8fNbqECl zRQ5LTAbUXjqroznFJapDwuQRYzbSs/z+/x7TRZY+LxhPAiTw2ujxNRL4frF9RTxkIZE JE2g== |
| 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:cc; bh=O78FZW+g790v1jNRDp1zMf0jkM8UlWCu4fYCipwCd6Y=; b=h59Gg/5rlhsrew0r93Cmn4Zqv+GAnJKqx0244oisgoueDHIeIB5KINzTbnxvrZM8jE BJvG9mRbOIq74XlqyQNOTbdROdBmgVr2l4nCLZdE3CBJYwuz8umWlJwhCBB6DnRQMapK CfstNpYzK9hP9qTM/jU21qB7klrqyo3IDMeGhsTNoW8AAsPWoZrGOFTUN+OY/+I/hd9r CaHNVZpFD8oxo7iciB5NF5Nz9wFpcpsCwyzeUyNjC3Ske22qGZRAld8Ws6SyP30UEIBU sbaoHX/GGOXt6GXSQisKXw4z1itnwtea2fkx7/YoW4LnL+okGbB7/j7b9+ZZT8RuIYIN nQCA== |
| X-Gm-Message-State | AG10YOTovKNprpJ+C29ohRR40cY12ujVJeahwYdUG/l+xwbJKdfjO19ELvURX08yy8IkPWxNw9vM6jzlCa4Dtg== |
| X-Received | by 10.107.135.30 with SMTP id j30mr2861299iod.103.1456399342748; Thu, 25 Feb 2016 03:22:22 -0800 (PST) |
| In-Reply-To | <56cecf47$0$3305$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 <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:103492 |
Show key headers only | View raw
On Thu, Feb 25, 2016 at 3:54 AM, ast <nomail@invalid.com> wrote:
> So we can conclude that inspect.isclass(x) is equivalent
> to isinstance(x, type)
>
> lets have a look at the source code of isclass:
>
> def isclass(object):
> """Return true if the object is a class.
>
> Class objects provide these attributes:
> __doc__ documentation string
> __module__ name of module in which this class was defined"""
> return isinstance(object, type)
Except Python 2 old-style classes (i.e. 2.x classes that aren't a
subclass of `object`) are not instances of `type`. Prior to new-style
classes, only built-in types were instances of `type`. An old-style
class is an instance of "classobj", and its instances have the
"instance" type.
>>> class A: pass
...
>>> type(A)
<type 'classobj'>
>>> type(A())
<type 'instance'>
Note that "classobj" and "instance" are instances of `type`.
The `isclass` check in Python 2 has to instead check
isinstance(object, (type, types.ClassType)).
>>> types.ClassType
<type 'classobj'>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to define what a class is ? "ast" <nomail@invalid.com> - 2016-02-24 09:08 +0100
Re: How to define what a class is ? Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-24 01:46 -0700
Re: How to define what a class is ? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-02-25 09:44 +1300
Re: How to define what a class is ? "ast" <nomail@invalid.com> - 2016-02-25 10:54 +0100
Re: How to define what a class is ? eryk sun <eryksun@gmail.com> - 2016-02-25 05:21 -0600
Re: How to define what a class is ? Ben Finney <ben+python@benfinney.id.au> - 2016-02-24 20:11 +1100
csiph-web