Skip to content

Commit f2274bd

Browse files
committed
replace __nonzero__ with __bool__
python3 deprecates __nonzero__ and introduces __bool__ This commit introduces __bool__ while maintaining python2 compatibility
1 parent 8137e6c commit f2274bd

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

myhdl/_Signal.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,10 @@ def __hash__(self):
323323
raise TypeError("Signals are unhashable")
324324

325325

326-
def __nonzero__(self):
327-
if self._val:
328-
return 1
329-
else:
330-
return 0
326+
def __bool__(self):
327+
return bool(self._val)
328+
329+
__nonzero__ = __bool__
331330

332331
# length
333332
def __len__(self):

myhdl/_intbv.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,10 @@ def __iter__(self):
114114
return iter([self[i] for i in range(self._nrbits-1, -1, -1)])
115115

116116
# logical testing
117-
def __nonzero__(self):
118-
if self._val:
119-
return 1
120-
else:
121-
return 0
117+
def __bool__(self):
118+
return bool(self._val)
119+
120+
__nonzero__ = __bool__
122121

123122
# length
124123
def __len__(self):

0 commit comments

Comments
 (0)