Skip to content

Commit 9a8d0dc

Browse files
committed
fix(bool): echo x where x has no $ resulted in pybool called
1 parent 86fbbad commit 9a8d0dc

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/pylib/pybool.nim

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ func `not`*(self): PyBool{.borrow.}
2020
genBin `and`
2121
genBin `or`
2222

23-
converter pybool*[T](x: T): PyBool # forward decl
24-
func `not`*[T: not PyBool and not bool](nself: T): PyBool = not nself.pybool
25-
func `and`*[T: not PyBool and not bool](nself, npyb: T): T =
26-
if nself.pybool: npyb else: nself
27-
func `or` *[T: not PyBool and not bool](nself, npyb: T): T =
28-
if nself.pybool: nself else: npyb
29-
3023
func repr*(self): string =
3124
## Returns "True" or "False"
3225
if bool(self == True): "True"
@@ -67,9 +60,9 @@ template toBool*[T](arg: T): bool =
6760
# If we have len proc for this object
6861
when compiles(arg.len):
6962
arg.len > 0
63+
elif T is SomeNumber:
7064
# If we can compare if it's not 0
71-
elif compiles(arg != 0):
72-
arg != 0
65+
arg != 0 # works for NaN
7366
# If we can compare if it's greater than 0
7467
elif compiles(arg > 0):
7568
arg > 0 or arg < 0
@@ -92,6 +85,12 @@ converter pybool*[T](x: T): PyBool =
9285
## then there'll be ## compile-error for `repr(<list>)`
9386
PyBool toBool x
9487
88+
func `not`*[T](nself: T): PyBool = not nself.pybool
89+
func `and`*[T](nself, npyb: T): T =
90+
if nself.pybool: npyb else: nself
91+
func `or` *[T](nself, npyb: T): T =
92+
if nself.pybool: nself else: npyb
93+
9594
proc bool*[T](arg: T): PyBool = pybool(arg) ## Alias for `pybool`_
9695
9796
func all*[T](iter: Iterable[T]): PyBool =

0 commit comments

Comments
 (0)