Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!feeder2.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail 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; 'context': 0.04; 'thread,': 0.04; '(python': 0.05; 'behave': 0.07; 'function,': 0.07; 'python': 0.08; 'builtin': 0.09; 'callable': 0.09; 'callable.': 0.09; 'foo': 0.09; 'foo,': 0.09; 'def': 0.14; '16,': 0.15; 'cc:addr:python-list': 0.15; 'roy': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'wed,': 0.17; 'language': 0.17; 'wrote:': 0.18; 'functions,': 0.18; 'received:209.85.210.174': 0.18; 'received :mail-iy0-f174.google.com': 0.18; '(which': 0.19; 'cc:no real name:2**0': 0.21; 'issue.': 0.21; "doesn't": 0.23; 'fine,': 0.23; 'least,': 0.23; 'header:In-Reply-To:1': 0.23; 'cc:2**0': 0.25; 'work,': 0.26; 'function': 0.27; 'url:mailman': 0.27; 'discussed': 0.28; 'pass': 0.28; 'fine.': 0.28; 'fix': 0.29; 'cc:addr:python.org': 0.29; 'message-id:@mail.gmail.com': 0.29; 'second': 0.29; 'print': 0.29; 'class': 0.29; 'broke': 0.30; 'differently': 0.30; 'now)': 0.30; 'url:03': 0.30; "didn't": 0.30; 'nov': 0.31; 'pm,': 0.31; 'objects': 0.32; 'url:listinfo': 0.32; 'does': 0.32; "can't": 0.32; 'quite': 0.32; 'actually': 0.33; '(as': 0.34; 'skip:@ 10': 0.34; 'changing': 0.34; 'however,': 0.34; 'notes': 0.35; 'certain': 0.35; 'unless': 0.35; 'url:python': 0.35; 'before.': 0.36; 'class.': 0.36; 'thread': 0.36; 'url:pipermail': 0.36; 'but': 0.37; 'issue': 0.37; 'steven': 0.38; 'run': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'url:org': 0.38; 'returned': 0.38; 'subject:: ': 0.39; 'difference': 0.40; 'happens': 0.40; 'received:209': 0.40; 'behind': 0.40; '2011': 0.62; 'eliminate': 0.63; 'making': 0.67; 'url:2011': 0.71; '-0500,': 0.84; '11:43': 0.84; 'imagined': 0.84; 'self.': 0.84; 'url:answers': 0.84; 'url:topic': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=z4eYQD/L+ff42UnQyaJOPyYxTGUuK7vYZhwjnNtMLf4=; b=AhyYN0cw+FtBQ57AQorZvHomHxMqTd4vAt8qfCb8aqvfprTIrye4tBwJV2+pYb0+sq ZFJAQFl/vzZTZatBqkz8x9xWr20eg8cs8Zw5lGFYsikrANC+MTq/Hm7SkAAlx7fWFu5S T931lNHBDHXlDFVnHUovy21X+BKvsxwollUS8= MIME-Version: 1.0 In-Reply-To: <4ec490ec$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <4ec490ec$0$30003$c3e8da3$5496439d@news.astraweb.com> From: Devin Jeanpierre Date: Thu, 17 Nov 2011 01:20:43 -0500 Subject: Re: staticmethod makes my brain hurt To: "Steven D'Aprano" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 87 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1321510888 news.xs4all.nl 6884 [2001:888:2000:d::a6]:46887 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15807 > However, the fix is not as simple as merely making staticmethod objects > callable. This was discussed at the 2011 language summit: > > http://www.boredomandlaziness.org/2011/03/python-language-summit-rough-no= tes.html > > See also this thread: > > http://mail.python.org/pipermail/python-dev/2011-March/109090.html The notes didn't actually mention what was discussed, but re the second thread, the issue was not changing staticmethod to be callable. Making staticmethod callable is fine, but __get__ still has to return the original function, not self. The context of the second thread was that staticmethod was imagined as one way to eliminate the difference between C and Python functions, when added to a class. But this doesn't quite work, unless staticmethod.__get__ returned self (which broke for related reasons). If it returns the original function (as it does now) then the issue is unresolved: C functions still behave differently from Python functions, so you can't quite just hide them behind a staticmethod and let everything remain the same. It doesn't eliminate the difference in behavior in certain circumstances, e.g.: class MyClass: foo =3D staticmethod(foo) class MyOtherClass: foo =3D MyClass.foo MyOtherClass().foo() # what happens if foo is builtin vs pure-Python? In the context of this thread, though, just making it callable without modifying __get__ is fine. Or at least, I don't see the issue. Devin On Wed, Nov 16, 2011 at 11:43 PM, Steven D'Aprano wrote: > On Wed, 16 Nov 2011 21:30:57 -0500, Roy Smith wrote: > >> When I run this (python 2.6.1): >> >> class C: >> =C2=A0 =C2=A0 @staticmethod >> =C2=A0 =C2=A0 def foo(): >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 pass >> =C2=A0 =C2=A0 print "inside", foo, callable(foo) >> >> print "outside", C.foo, callable(C.foo) >> >> I get: >> >> inside False >> outside True >> >> I don't understand. =C2=A0Why is foo not callable inside of the class >> definition? > > > This has come up before. > > http://bytes.com/topic/python/answers/34396-static-method-object-not-call= able > > http://bytes.com/topic/python/answers/462734-make-staticmethod-objects-ca= llable > > > However, the fix is not as simple as merely making staticmethod objects > callable. This was discussed at the 2011 language summit: > > http://www.boredomandlaziness.org/2011/03/python-language-summit-rough-no= tes.html > > See also this thread: > > http://mail.python.org/pipermail/python-dev/2011-March/109090.html > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list >