@@ -20,13 +20,6 @@ func `not`*(self): PyBool{.borrow.}
20
20
genBin `and`
21
21
genBin `or`
22
22
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
-
30
23
func repr* (self): string =
31
24
# # Returns "True" or "False"
32
25
if bool (self == True): " True"
@@ -67,9 +60,9 @@ template toBool*[T](arg: T): bool =
67
60
# If we have len proc for this object
68
61
when compiles(arg.len):
69
62
arg.len > 0
63
+ elif T is SomeNumber:
70
64
# If we can compare if it's not 0
71
- elif compiles(arg != 0):
72
- arg != 0
65
+ arg != 0 # works for NaN
73
66
# If we can compare if it's greater than 0
74
67
elif compiles(arg > 0):
75
68
arg > 0 or arg < 0
@@ -92,6 +85,12 @@ converter pybool*[T](x: T): PyBool =
92
85
## then there'll be ## compile-error for `repr(<list>)`
93
86
PyBool toBool x
94
87
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
+
95
94
proc bool *[T](arg: T): PyBool = pybool(arg) ## Alias for `pybool`_
96
95
97
96
func all*[T](iter: Iterable[T]): PyBool =
0 commit comments