Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21199
| References | <mailman.373.1330851839.3037.python-list@python.org> <4f53433c$0$29989$c3e8da3$5496439d@news.astraweb.com> |
|---|---|
| Date | 2012-03-04 21:14 +0700 |
| Subject | Re: Jython callable. How? |
| From | Sirotin Roman <web.elektro.net@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.381.1330870489.3037.python-list@python.org> (permalink) |
> Perhaps if you show us what you actually do, and what happens, we might
> be able to tell you what is happening. Please COPY AND PASTE the full
> traceback.
Here is my code:
# Trying to make callable staticmethod
class sm(staticmethod):
def __call__(self, *args, **kwargs):
""" I know here is one more potential problem, because object
passed instead of real class """
return self.__get__(None, object)(*args, **kwargs)
issubclass(sm, Callable)
class Foo(object):
@sm
def bar():
print("ololo")
print("inside", bar, callable(bar), bar())
if __name__=="__main__":
print("class outise", Foo.bar, callable(Foo.bar), Foo.bar())
f = Foo()
print("instance outside", f.bar, callable(f.bar), f.bar())
cpython output:
ololo
('inside', <__main__.sm object at 0xb72b404c>, True, None)
ololo
('class outise', <function bar at 0xb72a680c>, True, None)
ololo
('instance outside', <function bar at 0xb72a680c>, True, None)
jython output:
Traceback (most recent call last):
File "sm.py", line 17, in <module>
class Foo(object):
File "sm.py", line 23, in Foo
print("inside", bar, callable(bar), bar())
TypeError: 'staticmethod' object is not callable
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Jython callable. How? Sirotin Roman <web.elektro.net@gmail.com> - 2012-03-04 16:03 +0700
Re: Jython callable. How? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-03-04 10:26 +0000
Re: Jython callable. How? Sirotin Roman <web.elektro.net@gmail.com> - 2012-03-04 21:14 +0700
csiph-web