-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
js backend: support functor style classes that define __call__ specia…
…l method. this is supported by checking if the class has a __call__ method, and if it has, then move the def of __call__ into the constructor, bind it to this, copy attributes and __proto__ from this, and then return __call__.
- Loading branch information
hartsantler
committed
Sep 19, 2015
1 parent
90611c4
commit 4bfb360
Showing
2 changed files
with
33 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
"""custom callable""" | ||
from runtime import * | ||
|
||
class A: | ||
def __init__(self): | ||
self.x = 5 | ||
|
||
def __call__(self): | ||
print self.x | ||
return 'XXX' | ||
|
||
def foo(self): | ||
return self.x | ||
|
||
|
||
def main(): | ||
print 'testing __call__' | ||
a = A() | ||
TestError(a.x == 5) | ||
TestError( a()=='XXX' ) | ||
assert a.x == 5 | ||
assert a() == 'XXX' | ||
assert a.__call__() == 'XXX' | ||
assert a.foo() == 5 | ||
print 'ok' | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters