Skip to content

Commit 33ecc77

Browse files
committed
feat(builtins): bool; fix(py): neval regarded user-define instance as false
1 parent 045eb6e commit 33ecc77

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

Python/bltinmodule.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ implBltinFunc buildClass(funcObj: PyFunctionObject, name: PyStrObject), "__build
108108

109109

110110
registerBltinObject("NotImplemented", pyNotImplemented)
111+
registerBltinObject("bool", pyBoolObjectType)
111112
registerBltinObject("Ellipsis", pyEllipsis)
112113
registerBltinObject("None", pyNone)
113114
registerBltinObject("type", pyTypeObjectType)

Python/neval.nim

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import builtindict
1010
import traceback
1111
import ../Objects/[pyobject, baseBundle, tupleobject, listobject, dictobject,
1212
sliceobject, codeobject, frameobject, funcobject, cellobject,
13-
setobject, notimplementedobject,
13+
setobject, notimplementedobject, boolobjectImpl,
1414
exceptionsImpl, moduleobject, methodobject]
1515
import ../Utils/utils
1616

@@ -102,13 +102,7 @@ template doBinaryContain: PyObject =
102102

103103
# "fast" because check if it's a bool object first and save the callMagic(bool)
104104
template getBoolFast(obj: PyObject): bool =
105-
var ret: bool
106-
if obj.ofPyBoolObject:
107-
ret = PyBoolObject(obj).b
108-
# if user defined class tried to return non bool,
109-
# the magic method will return an exception
110-
let boolObj = top.callMagic(bool, handleExcp=true)
111-
PyBoolObject(boolObj).b
105+
PyObject_IsTrue(obj)
112106

113107
# if declared as a local variable, js target will fail. See gh-10651
114108
when defined(js):

0 commit comments

Comments
 (0)