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


Groups > comp.lang.python > #60835

Re: Extending the 'function' built-in class

Date 2013-12-01 13:43 -0600
From Tim Chase <python.list@tim.thechases.com>
Subject Re: Extending the 'function' built-in class
References <529b8ba2$0$2270$426a74cc@news.free.fr>
Newsgroups comp.lang.python
Message-ID <mailman.3439.1385926961.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 2013-12-01 19:18, G. wrote:
> Hi, I can't figure out how I can extend the 'function' built-in
> class. I tried: class test(function):
>     def test(self):
>       print("test")
> but I get an error. Is it possible ?

While I don't have an answer, I did find this interesting.  First,
"function" doesn't seem to be in the default __buitin__ namespace:

  >>> function
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  NameError: name 'function' is not defined

I presume you're doing it with the following:

  >>> from types import FunctionType
  >>> class MyFunc(FunctionType):
  ...     pass
  ... 
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  TypeError: Error when calling the metaclass bases
      type 'function' is not an acceptable base type

but, as you mention, the inability to subclass it is somewhat
peculiar.  It appears to be metaclass-related.

I'm not quite sure *why* one might want to subclass FunctionType, but
I'm also not sure why you should be *prevented* from subclassing it.

-tkc

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


Thread

Extending the 'function' built-in class "G." <grumsk@grumsk.tz> - 2013-12-01 19:18 +0000
  Re: Extending the 'function' built-in class Roy Smith <roy@panix.com> - 2013-12-01 14:30 -0500
    Re: Extending the 'function' built-in class "G." <grumsk@grumsk.tz> - 2013-12-01 19:37 +0000
  Re: Extending the 'function' built-in class Tim Chase <python.list@tim.thechases.com> - 2013-12-01 13:43 -0600
  Re: Extending the 'function' built-in class Gary Herron <gary.herron@islandtraining.com> - 2013-12-01 11:38 -0800
    Re: Extending the 'function' built-in class "G." <grumsk@grumsk.tz> - 2013-12-01 20:13 +0000
  Re: Extending the 'function' built-in class Robert Kern <robert.kern@gmail.com> - 2013-12-01 20:18 +0000
  Re: Extending the 'function' built-in class Mark Janssen <dreamingforward@gmail.com> - 2013-12-01 17:26 -0800
  Re: Extending the 'function' built-in class alex23 <wuwei23@gmail.com> - 2013-12-02 12:24 +1000
  Re: Extending the 'function' built-in class Steven D'Aprano <steve@pearwood.info> - 2013-12-02 07:01 +0000
    Re: Extending the 'function' built-in class "G." <grumsk@grumsk.tz> - 2013-12-02 09:32 +0000

csiph-web