Skip to content

Commit c7f8b92

Browse files
committed
Because instances of Falsy are falsy, `func.im_self` in call_function() of xpython/pyvm2.ptreated them as nonexistent and did not add the self parameter to the argument list. The problem was exhibited on Python 2.7.
1 parent 2d05582 commit c7f8b92

File tree

10 files changed

+19
-1
lines changed

10 files changed

+19
-1
lines changed
647 Bytes
Binary file not shown.
647 Bytes
Binary file not shown.
647 Bytes
Binary file not shown.
721 Bytes
Binary file not shown.
805 Bytes
Binary file not shown.
556 Bytes
Binary file not shown.
556 Bytes
Binary file not shown.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# See https://github.com/nedbat/byterun/pull/33:
2+
#
3+
# Because instances of Falsy are falsy, `func.im_self` in
4+
# call_function() of xpython/pyvm2.ptreated them as nonexistent and
5+
# did not add the self parameter to the argument list.
6+
#
7+
# The problem was exhibited on Python 2.7.
8+
class Falsy(object):
9+
def __bool__(self):
10+
return False
11+
__nonzero__ = __bool__
12+
def do_stuff(self):
13+
pass
14+
15+
Falsy().do_stuff()

test/test_basic.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ def test_globals(self):
2626
def test_inplace_operators(self):
2727
self.do_one()
2828

29+
def test_bound_method_on_falsy_objects(self):
30+
self.do_one()
31+
2932
if PY2:
3033
def test_inplace_division(self):
3134
self.assert_ok("""\

xpython/pyvm2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ def call_function(self, arg, args, kwargs):
774774
func = self.pop()
775775
if hasattr(func, "im_func"):
776776
# Methods get self as an implicit first parameter.
777-
if func.im_self:
777+
if func.im_self is not None:
778778
posargs.insert(0, func.im_self)
779779
# The first parameter must be the correct type.
780780
if not isinstance(posargs[0], func.im_class):

0 commit comments

Comments
 (0)