Skip to content

Commit 9d1ac75

Browse files
committed
Remove more Python 2 legacy code (explicit inheritance from object, importing collections.Mapping).
1 parent 504aa89 commit 9d1ac75

File tree

14 files changed

+24
-32
lines changed

14 files changed

+24
-32
lines changed

examples/example5-introspection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# stages, and new members with names not starting with "_" are to be registered
1111
# for the next stage.
1212

13-
class SimplePipeline(object):
13+
class SimplePipeline:
1414
""" Pipeline builder with auto generation of pipeline registers. """
1515

1616
def __init__(self):

ipynb-examples/example5-introspection.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"\n",
3939
"pyrtl.reset_working_block()\n",
4040
"\n",
41-
"class SimplePipeline(object):\n",
41+
"class SimplePipeline:\n",
4242
" def __init__(self):\n",
4343
" self._pipeline_register_map = {}\n",
4444
" self._current_stage_num = 0\n",

pyrtl/analysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def _bits_ports_and_isrom_from_memory(mem):
135135
# | | | | | | \| \__> / \| \| /~~\ |_ | .__/ | .__/
136136
#
137137

138-
class TimingAnalysis(object):
138+
class TimingAnalysis:
139139
"""Timing analysis estimates the timing delays in the block
140140
141141
TimingAnalysis has an :py:attr:`~.TimingAnalysis.timing_map` object that

pyrtl/compilesim.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import platform
99
import sys
1010
import _ctypes
11+
from collections.abc import Mapping
1112

1213
from .core import working_block, Block
1314
from .wire import Input, Output, Const, WireVector, Register
@@ -16,11 +17,6 @@
1617
from .simulation import SimulationTrace, _trace_sort_key
1718
from .helperfuncs import infer_val_and_bitwidth
1819

19-
try:
20-
from collections.abc import Mapping
21-
except ImportError:
22-
from collections import Mapping
23-
2420

2521
__all__ = ['CompiledSimulation']
2622

@@ -56,7 +52,7 @@ def __eq__(self, other):
5652
return all(self[x] == other.get(x, 0) for x in self)
5753

5854

59-
class CompiledSimulation(object):
55+
class CompiledSimulation:
6056
"""Simulate a block, compiling to C for efficiency.
6157
6258
This module provides significant speed improvements over

pyrtl/conditional.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def currently_under_condition() -> bool:
185185
# `conditional_assignment` and `otherwise`, both visible in the pyrtl module, are
186186
# defined as instances (hopefully the only and unchanging instances) of the following
187187
# two types.
188-
class _ConditionalAssignment(object):
188+
class _ConditionalAssignment:
189189
def __init__(self):
190190
self.defaults = {}
191191

@@ -208,7 +208,7 @@ def __exit__(self, *exc_info):
208208
_reset_conditional_state() # sets _depth back to 0
209209

210210

211-
class _Otherwise(object):
211+
class _Otherwise:
212212
def __enter__(self):
213213
_push_condition(otherwise)
214214

pyrtl/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def _compare_error(self, other):
232232
__ge__ = _compare_error
233233

234234

235-
class Block(object):
235+
class Block:
236236
"""Block encapsulates a netlist.
237237
238238
A Block in PyRTL is the class that stores a netlist and provides basic
@@ -977,7 +977,7 @@ def reset_working_block():
977977
_singleton_block = Block()
978978

979979

980-
class set_working_block(object):
980+
class set_working_block:
981981
""" Set the working block to be the block passed as argument.
982982
Compatible with the `with` statement.
983983
@@ -1037,7 +1037,7 @@ def set_debug_mode(debug=True):
10371037
_py_regex = r'^[^\d\W]\w*\Z'
10381038

10391039

1040-
class _NameIndexer(object):
1040+
class _NameIndexer:
10411041
""" Provides internal names that are based on a prefix and an index. """
10421042
def __init__(self, internal_prefix='_sani_temp'):
10431043
self.internal_prefix = internal_prefix

pyrtl/helperfuncs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ def find_loop(block=None):
891891
wires_left, logic_left = result
892892
import random
893893

894-
class _FilteringState(object):
894+
class _FilteringState:
895895
def __init__(self, dst_w):
896896
self.dst_w = dst_w
897897
self.arg_num = -1
@@ -987,7 +987,7 @@ def _print_netlist_latex(netlist):
987987
display(Latex(out))
988988

989989

990-
class _NetCount(object):
990+
class _NetCount:
991991
""" Helper class to track when to stop an iteration that depends on number of nets
992992
993993
Mainly useful for iterations that are for optimization

pyrtl/memory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def name(self, n):
8686
as_wires(self).name = n
8787

8888

89-
class MemBlock(object):
89+
class MemBlock:
9090
"""MemBlock is the object for specifying block memories. It can be indexed like an
9191
array for both reading and writing. Writes under a conditional are automatically
9292
converted to enabled writes. Consider the following examples where ``addr``,

pyrtl/passes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def _optimize_inverter_chains(block, skip_sanity_check=False):
208208
block.sanity_check()
209209

210210

211-
class _ProducerList(object):
211+
class _ProducerList:
212212
""" Maps from wire to its immediate producer and finds ultimate producers. """
213213
def __init__(self):
214214
self.dict = {} # map from wirevector to its direct producer wirevector

pyrtl/rtllib/aes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
# full independent hardware units) would be a plus as well
4747

4848

49-
class AES(object):
49+
class AES:
5050
def __init__(self):
5151
self.memories_built = False
5252
self._key_len = 128

pyrtl/rtllib/matrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from ..helperfuncs import formatted_str_to_val
1010

1111

12-
class Matrix(object):
12+
class Matrix:
1313
''' Class for making a Matrix using PyRTL.
1414
1515
Provides the ability to perform different matrix operations.

pyrtl/rtllib/muxes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def _sparse_mux(sel, vals):
105105
return pyrtl.select(sel[-1], falsecase=false_result, truecase=true_result)
106106

107107

108-
class MultiSelector(object):
108+
class MultiSelector:
109109
""" The MultiSelector allows you to specify multiple wire value results
110110
for a single select wire.
111111

pyrtl/simulation.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import re
1010
import sys
1111
import typing
12+
from collections.abc import Mapping
1213

1314
from .pyrtlexceptions import PyrtlError, PyrtlInternalError
1415
from .core import working_block, PostSynthBlock, _PythonSanitizer, Block
@@ -18,19 +19,14 @@
1819
from .helperfuncs import val_to_signed_integer, infer_val_and_bitwidth
1920
from .importexport import _VerilogSanitizer
2021

21-
try:
22-
from collections.abc import Mapping
23-
except ImportError:
24-
from collections import Mapping
25-
2622
# ----------------------------------------------------------------
2723
# __ ___ __
2824
# /__` | |\/| | | | /\ | | / \ |\ |
2925
# .__/ | | | \__/ |___ /~~\ | | \__/ | \|
3026
#
3127

3228

33-
class Simulation(object):
29+
class Simulation:
3430
"""A class for simulating blocks of logic step by step.
3531
3632
A Simulation step works as follows:
@@ -488,7 +484,7 @@ def _mem_update(self, net):
488484
#
489485

490486

491-
class FastSimulation(object):
487+
class FastSimulation:
492488
"""A class for running JIT-to-python implementations of blocks.
493489
494490
A Simulation step works as follows:
@@ -994,7 +990,7 @@ def make_split(
994990
# | | \ /~~\ \__, |___
995991
#
996992

997-
class WaveRenderer(object):
993+
class WaveRenderer:
998994
"""Render a SimulationTrace to the terminal.
999995
1000996
See ``examples/renderer-demo.py``, which renders traces with various
@@ -1460,7 +1456,7 @@ def __getitem__(self, key):
14601456
return self.__data[key]
14611457

14621458

1463-
class SimulationTrace(object):
1459+
class SimulationTrace:
14641460
""" Storage and presentation of simulation waveforms. """
14651461

14661462
def __init__(self, wires_to_track: list[WireVector] = None,

pyrtl/wire.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def next_tempvar_name(name=""):
5858
WireVectorLike = Union["WireVector", int, str, bool]
5959

6060

61-
class WireVector(object):
61+
class WireVector:
6262
"""The main class for describing the connections between operators.
6363
6464
``WireVectors`` act much like a list of wires, except that there is no "contained"
@@ -1244,7 +1244,7 @@ class Register(WireVector):
12441244
# reg <<= 5 # error
12451245
# a <<= reg.next # error
12461246
# reg.next = 5 # error
1247-
class _Next(object):
1247+
class _Next:
12481248
"""Type returned by the ``Register.next`` property.
12491249
12501250
This class allows unconditional assignments (``<<=``, ``__ilshift__``) and

0 commit comments

Comments
 (0)