Skip to content

Commit 6746741

Browse files
Need to get PyObject 's attribute which is not necessarily a dict
1 parent a6303de commit 6746741

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
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_objects.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pythonmonkey as pm
22
import sys
3+
from io import StringIO
34

45

56
def test_eval_pyobjects():
@@ -170,4 +171,14 @@ def test_toPrimitive_stdin():
170171

171172
def test_constructor_stdin():
172173
constructor = pm.eval("(obj) => { return obj.constructor; }")(sys.stdin)
173-
assert repr(constructor).__contains__("<pythonmonkey.JSFunctionProxy object at")
174+
assert repr(constructor).__contains__("<pythonmonkey.JSFunctionProxy object at")
175+
176+
177+
def test_stdin_tty_console_printing():
178+
temp_out = StringIO()
179+
sys.stdout = temp_out
180+
obj = {}
181+
obj['stdin'] = sys.stdin
182+
obj['stdin'].isTTY = sys.stdin.isatty()
183+
pm.eval('''(function iife(obj){console.log(obj['stdin'].isTTY);})''')(obj)
184+
assert temp_out.getvalue() == "\x1b[33mfalse\x1b[39m\n"

0 commit comments

Comments
 (0)