Jython callable. How?

S

Sirotin Roman

Hi.
How exactly jython decides is object callable or not? I defined
__call__ method but interpreter says it's still not callable.
BTW, my code works in cpython
 
S

Steven D'Aprano

Hi.
How exactly jython decides is object callable or not? I defined __call__
method but interpreter says it's still not callable. BTW, my code works
in cpython

Works for me.

steve@runes:~$ jython
*sys-package-mgr*: processing modified jar, '/usr/share/java/servlet-
api-2.5.jar'
Jython 2.5.1+ (Release_2_5_1, Aug 4 2010, 07:18:19)
[OpenJDK Client VM (Sun Microsystems Inc.)] on java1.6.0_18
Type "help", "copyright", "credits" or "license" for more information..... def __call__(self):
.... return 42
....42


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.
 
S

Sirotin Roman

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top