brython-dev / brython

Brython (Browser Python) is an implementation of Python 3 running in the browser
BSD 3-Clause "New" or "Revised" License
6.4k stars 512 forks source link

cannot explicitly call a `@staticmethod` `__call__()` member function #2467

Closed fwyzard closed 4 months ago

fwyzard commented 5 months ago

Disclaimer

I'm trying to run in Brython a python application of which I'm not the main author, and I encountered a corner case where Brythin and regular python have a different behaviour.

I know that this piece of python code is ugly - I'm not even sure it is correct - but it works with regular python (3.10.12) and pypy (3.8.13/7.3.9), so maybe it should work also with Brython 🤷🏻‍♂️

I'll try to make the original code more sensible, but so far this is a minimal reproducer.


It looks like with Brython one cannot call explicitly the member function __call__ if it has the attribute @staticmethod:

class MyClass(object):
    @staticmethod
    def __call__(arg):
        print(f"MyClass.__call__({arg})")
        return arg

With python and pypy I get

>>> print(type(MyClass.__call__(42)))
MyClass.__call__(42)
<class 'int'>

>>> print(MyClass.__call__(42))
MyClass.__call__(42)
42

With Brython it looks like the function call is not executed, and I get

# print(type(MyClass.__call__(42)))
<class 'function'>

# print(MyClass.__call__(42))
<function MyClass.__call__>
fwyzard commented 4 months ago

Thanks!