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


Groups > comp.lang.python > #15807

Re: staticmethod makes my brain hurt

References <roy-DD1C5B.21305716112011@news.panix.com> <4ec490ec$0$30003$c3e8da3$5496439d@news.astraweb.com>
From Devin Jeanpierre <jeanpierreda@gmail.com>
Date 2011-11-17 01:20 -0500
Subject Re: staticmethod makes my brain hurt
Newsgroups comp.lang.python
Message-ID <mailman.2791.1321510888.27778.python-list@python.org> (permalink)

Show all headers | View raw


> 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-notes.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 = staticmethod(foo)

    class MyOtherClass:
        foo = 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
<steve+comp.lang.python@pearwood.info> wrote:
> On Wed, 16 Nov 2011 21:30:57 -0500, Roy Smith wrote:
>
>> When I run this (python 2.6.1):
>>
>> class C:
>>     @staticmethod
>>     def foo():
>>         pass
>>     print "inside", foo, callable(foo)
>>
>> print "outside", C.foo, callable(C.foo)
>>
>> I get:
>>
>> inside <staticmethod object at 0x421df0> False
>> outside <function foo at 0x41e6f0> True
>>
>> I don't understand.  Why 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-callable
>
> http://bytes.com/topic/python/answers/462734-make-staticmethod-objects-callable
>
>
> 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-notes.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
>

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


Thread

staticmethod makes my brain hurt Roy Smith <roy@panix.com> - 2011-11-16 21:30 -0500
  Re: staticmethod makes my brain hurt alex23 <wuwei23@gmail.com> - 2011-11-16 18:44 -0800
    Re: staticmethod makes my brain hurt Roy Smith <roy@panix.com> - 2011-11-16 21:52 -0500
  Re: staticmethod makes my brain hurt Ethan Furman <ethan@stoneleaf.us> - 2011-11-16 19:24 -0800
    Re: staticmethod makes my brain hurt alex23 <wuwei23@gmail.com> - 2011-11-17 18:31 -0800
  Re: staticmethod makes my brain hurt Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-11-17 04:43 +0000
    Re: staticmethod makes my brain hurt Roy Smith <roy@panix.com> - 2011-11-17 00:26 -0500
    Re: staticmethod makes my brain hurt Devin Jeanpierre <jeanpierreda@gmail.com> - 2011-11-17 01:20 -0500
  Re: staticmethod makes my brain hurt Dotan Cohen <dotancohen@gmail.com> - 2011-11-17 08:44 +0200
  Re: staticmethod makes my brain hurt Ian Kelly <ian.g.kelly@gmail.com> - 2011-11-17 00:37 -0700
  Re: staticmethod makes my brain hurt Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-11-17 10:17 +0100
  Re: staticmethod makes my brain hurt Dotan Cohen <dotancohen@gmail.com> - 2011-11-17 13:13 +0200
  Re: staticmethod makes my brain hurt Chris Angelico <rosuav@gmail.com> - 2011-11-17 22:38 +1100

csiph-web