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


Groups > comp.lang.python > #60835

Re: Extending the 'function' built-in class

Path csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; "subject:' ": 0.07; 'cc:addr:python-list': 0.11; 'def': 0.12; '*why*': 0.16; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'inability': 0.16; 'metaclass': 0.16; 'nameerror:': 0.16; 'presume': 0.16; 'subclass': 0.16; 'subclassing': 0.16; 'subject:class': 0.16; 'tried:': 0.16; 'typeerror:': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'appears': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'class.': 0.26; 'first,': 0.26; 'pass': 0.26; 'defined': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; "doesn't": 0.30; "i'm": 0.30; '"",': 0.31; 'file': 0.32; 'class': 0.32; 'extend': 0.32; 'figure': 0.32; 'quite': 0.32; '(most': 0.33; 'subject:the': 0.34; "can't": 0.35; 'but': 0.35; 'acceptable': 0.36; 'doing': 0.36; 'charset:us-ascii': 0.36; 'possible': 0.36; 'hi,': 0.36; 'should': 0.36; 'error.': 0.37; 'recent': 0.39; 'sure': 0.39; 'how': 0.40; "you're": 0.61; 'name': 0.63; 'default': 0.69; 'received:50.22': 0.84
Date Sun, 1 Dec 2013 13:43:59 -0600
From Tim Chase <python.list@tim.thechases.com>
To "G." <grumsk@grumsk.tz>
Subject Re: Extending the 'function' built-in class
In-Reply-To <529b8ba2$0$2270$426a74cc@news.free.fr>
References <529b8ba2$0$2270$426a74cc@news.free.fr>
X-Mailer Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
X-Get-Message-Sender-Via boston.accountservergroup.com: authenticated_id: tim@thechases.com
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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>
Newsgroups comp.lang.python
Message-ID <mailman.3439.1385926961.18130.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1385926961 news.xs4all.nl 16003 [2001:888:2000:d::a6]:33908
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:60835

Show key headers only | 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