Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103434

Re: How to define what a class is ?

From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: How to define what a class is ?
Date 2016-02-24 01:46 -0700
Message-ID <mailman.85.1456303651.20994.python-list@python.org> (permalink)
References <56cd64fb$0$9220$426a74cc@news.free.fr>

Show all headers | View raw


On Wed, Feb 24, 2016 at 1:08 AM, ast <nomail@invalid.com> 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)

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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