Skip to content

Commit 2e3274d

Browse files
Merge pull request #392 from Distributive-Network/philippe/389-fix
PyObject is not necessarily a dict in Iterable proxy when getting an attribute
2 parents a6303de + 055d412 commit 2e3274d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/PyIterableProxyHandler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ bool PyIterableProxyHandler::getOwnPropertyDescriptor(
294294

295295
PyObject *attrName = idToKey(cx, id);
296296
PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot);
297-
PyObject *item = PyDict_GetItemWithError(self, attrName);
297+
PyObject *item = PyObject_GetAttr(self, attrName);
298298

299299
return handleGetOwnPropertyDescriptor(cx, id, desc, item);
300300
}

tests/python/test_pythonmonkey_eval.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,14 @@ def test_console_array():
440440
items = [1, 2, 3]
441441
pm.eval('console.log')(items)
442442
assert temp_out.getvalue() == "[ \x1b[33m1\x1b[39m, \x1b[33m2\x1b[39m, \x1b[33m3\x1b[39m ]\n"
443+
444+
445+
def test_iterable_attribute_console_printing():
446+
temp_out = StringIO()
447+
sys.stdout = temp_out
448+
obj = {}
449+
obj['stdin'] = sys.stdin # sys.stdin is iterable
450+
assert hasattr(sys.stdin, '__iter__') == True
451+
obj['stdin'].isTTY = sys.stdin.isatty()
452+
pm.eval('''(function iife(obj){console.log(obj['stdin'].isTTY);})''')(obj)
453+
assert temp_out.getvalue() == "\x1b[33mfalse\x1b[39m\n"

0 commit comments

Comments
 (0)