cocotb 1.7.1__cp310-cp310-win32.whl → 1.8.0rc1__cp310-cp310-win32.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cocotb might be problematic. Click here for more details.

Files changed (87) hide show
  1. cocotb/__init__.py +7 -18
  2. cocotb/_sim_versions.py +16 -1
  3. cocotb/_version.py +1 -1
  4. cocotb/clock.py +8 -3
  5. cocotb/config.py +2 -1
  6. cocotb/decorators.py +40 -318
  7. cocotb/ipython_support.py +3 -1
  8. cocotb/libs/cocotb.dll +0 -0
  9. cocotb/libs/cocotb.exp +0 -0
  10. cocotb/libs/cocotb.lib +0 -0
  11. cocotb/libs/cocotbfli_modelsim.dll +0 -0
  12. cocotb/libs/cocotbfli_modelsim.exp +0 -0
  13. cocotb/libs/cocotbfli_modelsim.lib +0 -0
  14. cocotb/libs/cocotbutils.dll +0 -0
  15. cocotb/libs/cocotbutils.exp +0 -0
  16. cocotb/libs/cocotbutils.lib +0 -0
  17. cocotb/libs/cocotbvhpi_aldec.dll +0 -0
  18. cocotb/libs/cocotbvhpi_aldec.exp +0 -0
  19. cocotb/libs/cocotbvhpi_aldec.lib +0 -0
  20. cocotb/libs/cocotbvhpi_modelsim.dll +0 -0
  21. cocotb/libs/cocotbvhpi_modelsim.exp +0 -0
  22. cocotb/libs/cocotbvhpi_modelsim.lib +0 -0
  23. cocotb/libs/cocotbvpi_aldec.dll +0 -0
  24. cocotb/libs/cocotbvpi_aldec.exp +0 -0
  25. cocotb/libs/cocotbvpi_aldec.lib +0 -0
  26. cocotb/libs/cocotbvpi_ghdl.dll +0 -0
  27. cocotb/libs/cocotbvpi_ghdl.exp +0 -0
  28. cocotb/libs/cocotbvpi_ghdl.lib +0 -0
  29. cocotb/libs/cocotbvpi_icarus.exp +0 -0
  30. cocotb/libs/cocotbvpi_icarus.lib +0 -0
  31. cocotb/libs/cocotbvpi_icarus.vpl +0 -0
  32. cocotb/libs/cocotbvpi_modelsim.dll +0 -0
  33. cocotb/libs/cocotbvpi_modelsim.exp +0 -0
  34. cocotb/libs/cocotbvpi_modelsim.lib +0 -0
  35. cocotb/libs/embed.dll +0 -0
  36. cocotb/libs/embed.exp +0 -0
  37. cocotb/libs/embed.lib +0 -0
  38. cocotb/libs/gpi.dll +0 -0
  39. cocotb/libs/gpi.exp +0 -0
  40. cocotb/libs/gpi.lib +0 -0
  41. cocotb/libs/gpilog.dll +0 -0
  42. cocotb/libs/gpilog.exp +0 -0
  43. cocotb/libs/gpilog.lib +0 -0
  44. cocotb/libs/pygpilog.dll +0 -0
  45. cocotb/libs/pygpilog.exp +0 -0
  46. cocotb/libs/pygpilog.lib +0 -0
  47. cocotb/regression.py +32 -14
  48. cocotb/runner.py +541 -454
  49. cocotb/scheduler.py +35 -18
  50. cocotb/share/def/aldec.exp +0 -0
  51. cocotb/share/def/aldec.lib +0 -0
  52. cocotb/share/def/ghdl.exp +0 -0
  53. cocotb/share/def/ghdl.lib +0 -0
  54. cocotb/share/def/icarus.exp +0 -0
  55. cocotb/share/def/icarus.lib +0 -0
  56. cocotb/share/def/modelsim.def +2 -0
  57. cocotb/share/def/modelsim.exp +0 -0
  58. cocotb/share/def/modelsim.lib +0 -0
  59. cocotb/share/include/embed.h +1 -2
  60. cocotb/share/include/gpi.h +10 -15
  61. cocotb/share/include/vpi_user_ext.h +3 -0
  62. cocotb/share/lib/verilator/verilator.cpp +8 -4
  63. cocotb/share/makefiles/Makefile.inc +16 -4
  64. cocotb/share/makefiles/Makefile.sim +2 -2
  65. cocotb/share/makefiles/simulators/Makefile.icarus +19 -0
  66. cocotb/share/makefiles/simulators/Makefile.ius +12 -1
  67. cocotb/share/makefiles/simulators/Makefile.questa +2 -1
  68. cocotb/share/makefiles/simulators/Makefile.riviera +4 -0
  69. cocotb/share/makefiles/simulators/Makefile.vcs +4 -0
  70. cocotb/share/makefiles/simulators/Makefile.verilator +5 -1
  71. cocotb/share/makefiles/simulators/Makefile.xcelium +5 -1
  72. cocotb/simulator.cp310-win32.exp +0 -0
  73. cocotb/simulator.cp310-win32.lib +0 -0
  74. cocotb/simulator.cp310-win32.pyd +0 -0
  75. cocotb/task.py +325 -0
  76. cocotb/triggers.py +23 -7
  77. cocotb/types/logic_array.py +34 -3
  78. {cocotb-1.7.1.dist-info → cocotb-1.8.0rc1.dist-info}/METADATA +166 -149
  79. cocotb-1.8.0rc1.dist-info/RECORD +120 -0
  80. {cocotb-1.7.1.dist-info → cocotb-1.8.0rc1.dist-info}/WHEEL +1 -1
  81. cocotb/_vendor/find_libpython/__init__.py +0 -358
  82. cocotb/_vendor/find_libpython/__main__.py +0 -5
  83. cocotb/_vendor/find_libpython/_version.py +0 -5
  84. cocotb-1.7.1.dist-info/RECORD +0 -122
  85. {cocotb-1.7.1.dist-info → cocotb-1.8.0rc1.dist-info}/LICENSE +0 -0
  86. {cocotb-1.7.1.dist-info → cocotb-1.8.0rc1.dist-info}/entry_points.txt +0 -0
  87. {cocotb-1.7.1.dist-info → cocotb-1.8.0rc1.dist-info}/top_level.txt +0 -0
cocotb/task.py ADDED
@@ -0,0 +1,325 @@
1
+ # Copyright cocotb contributors
2
+ # Licensed under the Revised BSD License, see LICENSE for details.
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+ import collections.abc
5
+ import inspect
6
+ import os
7
+ import typing
8
+ import warnings
9
+ from asyncio import CancelledError, InvalidStateError
10
+
11
+ import cocotb
12
+ import cocotb.triggers
13
+ from cocotb import outcomes
14
+ from cocotb.log import SimLog
15
+ from cocotb.result import ReturnValue
16
+ from cocotb.utils import extract_coro_stack, lazy_property, remove_traceback_frames
17
+
18
+ T = typing.TypeVar("T")
19
+ Self = typing.TypeVar("Self")
20
+
21
+ # Sadly the Python standard logging module is very slow so it's better not to
22
+ # make any calls by testing a boolean flag first
23
+ _debug = "COCOTB_SCHEDULER_DEBUG" in os.environ
24
+
25
+
26
+ class Task(typing.Coroutine[typing.Any, typing.Any, T]):
27
+ """Concurrently executing task.
28
+
29
+ This class is not intended for users to directly instantiate.
30
+ Use :func:`cocotb.create_task` to create a Task object,
31
+ or use :func:`cocotb.start_soon` or :func:`cocotb.start` to
32
+ create a Task and schedule it to run.
33
+
34
+ .. versionchanged:: 1.8.0
35
+ Moved to the ``cocotb.task`` module.
36
+ """
37
+
38
+ _name: str = "Task" # class name of schedulable task
39
+ _id_count = 0 # used by the scheduler for debug
40
+
41
+ def __init__(self, inst):
42
+
43
+ if isinstance(inst, collections.abc.Coroutine):
44
+ self._natively_awaitable = True
45
+ elif inspect.isgenerator(inst):
46
+ self._natively_awaitable = False
47
+ elif inspect.iscoroutinefunction(inst):
48
+ raise TypeError(
49
+ "Coroutine function {} should be called prior to being "
50
+ "scheduled.".format(inst)
51
+ )
52
+ elif inspect.isasyncgen(inst):
53
+ raise TypeError(
54
+ "{} is an async generator, not a coroutine. "
55
+ "You likely used the yield keyword instead of await.".format(
56
+ inst.__qualname__
57
+ )
58
+ )
59
+ else:
60
+ raise TypeError(
61
+ f"{inst} isn't a valid coroutine! Did you forget to use the yield keyword?"
62
+ )
63
+ self._coro = inst
64
+ self._started = False
65
+ self._outcome: outcomes.Outcome = None
66
+ self._trigger: typing.Optional[cocotb.triggers.Trigger] = None
67
+ self._cancelled: typing.Optional[CancelledError] = None
68
+
69
+ self._task_id = self._id_count
70
+ type(self)._id_count += 1
71
+ self.__name__ = f"{type(self)._name} {self._task_id}"
72
+ self.__qualname__ = self.__name__
73
+
74
+ @lazy_property
75
+ def log(self) -> SimLog:
76
+ # Creating a logger is expensive, only do it if we actually plan to
77
+ # log anything
78
+ return SimLog(f"cocotb.{self.__qualname__}.{self._coro.__qualname__}")
79
+
80
+ @property
81
+ def retval(self) -> T:
82
+ """Return the result of the Task.
83
+
84
+ If the Task ran to completion, the result is returned.
85
+ If the Task failed with an exception, the exception is re-raised.
86
+ If the Task is not yet complete, a :exc:`RuntimeError` is raised.
87
+
88
+ .. deprecated:: 1.7.0
89
+ """
90
+ warnings.warn(
91
+ "Deprecated in favor of the result() method. "
92
+ "Replace `task.retval` with `task.result()`.",
93
+ DeprecationWarning,
94
+ stacklevel=2,
95
+ )
96
+ if self._outcome is None:
97
+ raise RuntimeError("coroutine is not complete")
98
+ return self._outcome.get()
99
+
100
+ @property
101
+ def _finished(self) -> bool:
102
+ """``True`` if the Task is finished executing.
103
+
104
+ .. deprecated:: 1.7.0
105
+ """
106
+ warnings.warn(
107
+ "Deprecated in favor of the done() method. "
108
+ "Replace `task._finished` with `task.done()`.",
109
+ DeprecationWarning,
110
+ stacklevel=2,
111
+ )
112
+ return self._outcome is not None
113
+
114
+ def __iter__(self: Self) -> Self:
115
+ # for use in "yield from" statements
116
+ return self
117
+
118
+ def __str__(self) -> str:
119
+ return f"<{self.__name__}>"
120
+
121
+ def _get_coro_stack(self) -> typing.Any:
122
+ """Get the coroutine callstack of this Task."""
123
+ coro_stack = extract_coro_stack(self._coro)
124
+
125
+ # Remove Trigger.__await__() from the stack, as it's not really useful
126
+ if self._natively_awaitable and len(coro_stack):
127
+ if coro_stack[-1].name == "__await__":
128
+ coro_stack.pop()
129
+
130
+ return coro_stack
131
+
132
+ def __repr__(self) -> str:
133
+ coro_stack = self._get_coro_stack()
134
+
135
+ if cocotb.scheduler._current_task is self:
136
+ fmt = "<{name} running coro={coro}()>"
137
+ elif self.done():
138
+ fmt = "<{name} finished coro={coro}() outcome={outcome}>"
139
+ elif self._trigger is not None:
140
+ fmt = "<{name} pending coro={coro}() trigger={trigger}>"
141
+ elif not self._started:
142
+ fmt = "<{name} created coro={coro}()>"
143
+ else:
144
+ fmt = "<{name} adding coro={coro}()>"
145
+
146
+ try:
147
+ coro_name = coro_stack[-1].name
148
+ # coro_stack may be empty if:
149
+ # - exhausted generator
150
+ # - finished coroutine
151
+ except IndexError:
152
+ coro_name = self._coro.__name__
153
+
154
+ repr_string = fmt.format(
155
+ name=self.__name__,
156
+ coro=coro_name,
157
+ trigger=self._trigger,
158
+ outcome=self._outcome,
159
+ )
160
+ return repr_string
161
+
162
+ def _advance(self, outcome: outcomes.Outcome) -> typing.Any:
163
+ """Advance to the next yield in this coroutine.
164
+
165
+ Args:
166
+ outcome: The :any:`outcomes.Outcome` object to resume with.
167
+
168
+ Returns:
169
+ The object yielded from the coroutine or None if coroutine finished
170
+
171
+ """
172
+ try:
173
+ self._started = True
174
+ return outcome.send(self._coro)
175
+ except ReturnValue as e:
176
+ self._outcome = outcomes.Value(e.retval)
177
+ except StopIteration as e:
178
+ self._outcome = outcomes.Value(e.value)
179
+ except BaseException as e:
180
+ self._outcome = outcomes.Error(
181
+ remove_traceback_frames(e, ["_advance", "send"])
182
+ )
183
+
184
+ def send(self, value: typing.Any) -> typing.Any:
185
+ return self._coro.send(value)
186
+
187
+ def throw(self, exc: BaseException) -> typing.Any:
188
+ return self._coro.throw(exc)
189
+
190
+ def close(self) -> None:
191
+ return self._coro.close()
192
+
193
+ def kill(self) -> None:
194
+ """Kill a coroutine."""
195
+ if self._outcome is not None:
196
+ # already finished, nothing to kill
197
+ return
198
+
199
+ if _debug:
200
+ self.log.debug("kill() called on coroutine")
201
+ # todo: probably better to throw an exception for anyone waiting on the coroutine
202
+ self._outcome = outcomes.Value(None)
203
+ cocotb.scheduler._unschedule(self)
204
+
205
+ def join(self) -> "cocotb.triggers.Join":
206
+ """Return a trigger that will fire when the wrapped coroutine exits."""
207
+ return cocotb.triggers.Join(self)
208
+
209
+ def has_started(self) -> bool:
210
+ """Return ``True`` if the Task has started executing."""
211
+ return self._started
212
+
213
+ def cancel(self, msg: typing.Optional[str] = None) -> None:
214
+ """Cancel a Task's further execution.
215
+
216
+ When a Task is cancelled, a :exc:`asyncio.CancelledError` is thrown into the Task.
217
+ """
218
+ self._cancelled = CancelledError(msg)
219
+ warnings.warn(
220
+ "Calling this method will cause a CancelledError to be thrown in the "
221
+ "Task sometime in the future.",
222
+ FutureWarning,
223
+ stacklevel=2,
224
+ )
225
+ self.kill()
226
+
227
+ def cancelled(self) -> bool:
228
+ """Return ``True`` if the Task was cancelled."""
229
+ return self._cancelled is not None
230
+
231
+ def done(self) -> bool:
232
+ """Return ``True`` if the Task has finished executing."""
233
+ return self._outcome is not None or self.cancelled()
234
+
235
+ def result(self) -> T:
236
+ """Return the result of the Task.
237
+
238
+ If the Task ran to completion, the result is returned.
239
+ If the Task failed with an exception, the exception is re-raised.
240
+ If the Task was cancelled, the CancelledError is re-raised.
241
+ If the coroutine is not yet complete, a :exc:`asyncio.InvalidStateError` is raised.
242
+ """
243
+ if not self.done():
244
+ raise InvalidStateError("result is not yet available")
245
+ elif self.cancelled():
246
+ raise self._cancelled
247
+ else:
248
+ return self._outcome.get()
249
+
250
+ def exception(self) -> typing.Optional[BaseException]:
251
+ """Return the exception of the Task.
252
+
253
+ If the Task ran to completion, ``None`` is returned.
254
+ If the Task failed with an exception, the exception is returned.
255
+ If the Task was cancelled, the CancelledError is re-raised.
256
+ If the coroutine is not yet complete, a :exc:`asyncio.InvalidStateError` is raised.
257
+ """
258
+ if not self.done():
259
+ raise InvalidStateError("result is not yet available")
260
+ elif self.cancelled():
261
+ raise self._cancelled
262
+ elif isinstance(self._outcome, outcomes.Error):
263
+ return self._outcome.error
264
+ else:
265
+ return None
266
+
267
+ def __bool__(self) -> bool:
268
+ """``True`` if Task is not done.
269
+
270
+ .. deprecated:: 1.7.0
271
+ """
272
+ warnings.warn(
273
+ "Deprecated in favor of the done() method. "
274
+ "Replace with `not task.done()`.",
275
+ DeprecationWarning,
276
+ stacklevel=2,
277
+ )
278
+ return not self.done()
279
+
280
+ def __await__(self) -> typing.Generator[typing.Any, typing.Any, T]:
281
+ # It's tempting to use `return (yield from self._coro)` here,
282
+ # which bypasses the scheduler. Unfortunately, this means that
283
+ # we can't keep track of the result or state of the coroutine,
284
+ # things which we expose in our public API. If you want the
285
+ # efficiency of bypassing the scheduler, remove the `@coroutine`
286
+ # decorator from your `async` functions.
287
+
288
+ # Hand the coroutine back to the scheduler trampoline.
289
+ return (yield self)
290
+
291
+
292
+ class _RunningCoroutine(Task[T]):
293
+ """
294
+ The result of calling a :any:`cocotb.coroutine` decorated coroutine.
295
+
296
+ All this class does is provide some extra attributes.
297
+
298
+ .. versionchanged:: 1.8.0
299
+ Moved to the ``cocotb.task`` module.
300
+ """
301
+
302
+ def __init__(self, inst, parent):
303
+ super().__init__(inst)
304
+ self._parent = parent
305
+ self.__doc__ = parent._func.__doc__
306
+ self.module = parent._func.__module__
307
+ self.funcname = parent._func.__name__
308
+
309
+
310
+ class _RunningTest(_RunningCoroutine[T]):
311
+ """
312
+ The result of calling a :class:`cocotb.test` decorated object.
313
+
314
+ All this class does is change ``__name__`` to show "Test" instead of "Task".
315
+
316
+ .. versionchanged:: 1.8.0
317
+ Moved to the ``cocotb.task`` module.
318
+ """
319
+
320
+ _name: str = "Test"
321
+
322
+ def __init__(self, inst, parent):
323
+ super().__init__(inst, parent)
324
+ self.__name__ = f"{type(self)._name} {self.funcname}"
325
+ self.__qualname__ = self.__name__
cocotb/triggers.py CHANGED
@@ -33,11 +33,12 @@ import warnings
33
33
  from collections.abc import Awaitable
34
34
  from decimal import Decimal
35
35
  from numbers import Real
36
- from typing import Optional, Union
36
+ from typing import Any, Coroutine, Optional, TypeVar, Union
37
37
 
38
38
  import cocotb
39
39
  from cocotb import outcomes, simulator
40
40
  from cocotb.log import SimLog
41
+ from cocotb.task import Task
41
42
  from cocotb.utils import (
42
43
  ParametrizedSingleton,
43
44
  get_sim_steps,
@@ -46,6 +47,8 @@ from cocotb.utils import (
46
47
  remove_traceback_frames,
47
48
  )
48
49
 
50
+ T = TypeVar("T")
51
+
49
52
 
50
53
  def _pointer_str(obj):
51
54
  """
@@ -189,6 +192,10 @@ class Timer(GPITrigger):
189
192
  When *units* is ``'step'``,
190
193
  the timestep is determined by the simulator (see :make:var:`COCOTB_HDL_TIMEPRECISION`).
191
194
 
195
+ round_mode (str, optional):
196
+ String specifying how to handle time values that sit between time steps
197
+ (one of ``'error'``, ``'round'``, ``'ceil'``, ``'floor'``).
198
+
192
199
  Examples:
193
200
 
194
201
  >>> await Timer(100, units='ps')
@@ -778,7 +785,7 @@ class _AggregateWaitable(Waitable):
778
785
 
779
786
  # Do some basic type-checking up front, rather than waiting until we
780
787
  # await them.
781
- allowed_types = (Trigger, Waitable, cocotb.decorators.Task)
788
+ allowed_types = (Trigger, Waitable, Task)
782
789
  for trigger in self.triggers:
783
790
  if not isinstance(trigger, allowed_types):
784
791
  raise TypeError(
@@ -793,8 +800,7 @@ class _AggregateWaitable(Waitable):
793
800
  return "{}({})".format(
794
801
  type(self).__qualname__,
795
802
  ", ".join(
796
- repr(Join(t)) if isinstance(t, cocotb.decorators.Task) else repr(t)
797
- for t in self.triggers
803
+ repr(Join(t)) if isinstance(t, Task) else repr(t) for t in self.triggers
798
804
  ),
799
805
  )
800
806
 
@@ -934,7 +940,12 @@ class ClockCycles(Waitable):
934
940
  return fmt.format(type(self).__qualname__, self.signal, self.num_cycles)
935
941
 
936
942
 
937
- async def with_timeout(trigger, timeout_time, timeout_unit="step"):
943
+ async def with_timeout(
944
+ trigger: Union[Trigger, Waitable, Task, Coroutine[Any, Any, T]],
945
+ timeout_time: Union[float, Decimal],
946
+ timeout_unit: str = "step",
947
+ round_mode: Optional[str] = None,
948
+ ) -> T:
938
949
  r"""
939
950
  Waits on triggers or coroutines, throws an exception if it waits longer than the given time.
940
951
 
@@ -972,12 +983,15 @@ async def with_timeout(trigger, timeout_time, timeout_unit="step"):
972
983
  await with_timeout(First(coro, event.wait()), 100, 'ns')
973
984
 
974
985
  Args:
975
- trigger (:class:`~cocotb.triggers.Trigger`, :class:`~cocotb.triggers.Waitable`, :class:`~cocotb.decorators.Task`, or :term:`python:coroutine`):
986
+ trigger (:class:`~cocotb.triggers.Trigger`, :class:`~cocotb.triggers.Waitable`, :class:`~cocotb.task.Task`, or :term:`python:coroutine`):
976
987
  A single object that could be right of an :keyword:`await` expression in cocotb.
977
988
  timeout_time (numbers.Real or decimal.Decimal):
978
989
  Simulation time duration before timeout occurs.
979
990
  timeout_unit (str, optional):
980
991
  Units of timeout_time, accepts any units that :class:`~cocotb.triggers.Timer` does.
992
+ round_mode (str, optional):
993
+ String specifying how to handle time values that sit between time steps
994
+ (one of ``'error'``, ``'round'``, ``'ceil'``, ``'floor'``).
981
995
 
982
996
  Returns:
983
997
  First trigger that completed if timeout did not occur.
@@ -1005,7 +1019,9 @@ async def with_timeout(trigger, timeout_time, timeout_unit="step"):
1005
1019
  shielded = False
1006
1020
  else:
1007
1021
  shielded = True
1008
- timeout_timer = cocotb.triggers.Timer(timeout_time, timeout_unit)
1022
+ timeout_timer = cocotb.triggers.Timer(
1023
+ timeout_time, timeout_unit, round_mode=round_mode
1024
+ )
1009
1025
  res = await First(timeout_timer, trigger)
1010
1026
  if res is timeout_timer:
1011
1027
  if not shielded:
@@ -28,6 +28,8 @@ class LogicArray(Array[Logic]):
28
28
  used.
29
29
  Like :class:`Array`, if no *range* argument is given, it is deduced from the length
30
30
  of the iterable or bit string used to initialize the variable.
31
+ If a *range* argument is given, but no value,
32
+ the array is filled with the default value of Logic().
31
33
 
32
34
  .. code-block:: python3
33
35
 
@@ -37,12 +39,15 @@ class LogicArray(Array[Logic]):
37
39
  >>> LogicArray([0, True, "X"])
38
40
  LogicArray('01X', Range(2, 'downto', 0))
39
41
 
40
- >>> LogicArray(0xA) # picks smallest range that can fit the value
42
+ >>> LogicArray(0xA) # picks smallest range that can fit the value
41
43
  LogicArray('1010', Range(3, 'downto', 0))
42
44
 
43
- >>> LogicArray(-4, Range(0, "to", 3)) # will sign-extend
45
+ >>> LogicArray(-4, Range(0, "to", 3)) # will sign-extend
44
46
  LogicArray('1100', Range(0, 'to', 3))
45
47
 
48
+ >>> LogicArray(range=Range(0, "to", 3)) # default values
49
+ LogicArray('XXXX', Range(0, 'to', 3))
50
+
46
51
  :class:`LogicArray`\ s support the same operations as :class:`Array`;
47
52
  however, it enforces the condition that all elements must be a :class:`Logic`.
48
53
 
@@ -115,12 +120,38 @@ class LogicArray(Array[Logic]):
115
120
 
116
121
  __slots__ = ()
117
122
 
123
+ @typing.overload
118
124
  def __init__(
119
125
  self,
120
126
  value: typing.Union[int, typing.Iterable[LogicConstructibleT], BinaryValue],
127
+ range: typing.Optional[Range],
128
+ ):
129
+ ...
130
+
131
+ @typing.overload
132
+ def __init__(
133
+ self,
134
+ value: typing.Union[
135
+ int, typing.Iterable[LogicConstructibleT], BinaryValue, None
136
+ ],
137
+ range: Range,
138
+ ):
139
+ ...
140
+
141
+ def __init__(
142
+ self,
143
+ value: typing.Union[
144
+ int, typing.Iterable[LogicConstructibleT], BinaryValue, None
145
+ ] = None,
121
146
  range: typing.Optional[Range] = None,
122
147
  ) -> None:
123
- if isinstance(value, int):
148
+ if value is None and range is None:
149
+ raise ValueError(
150
+ "at least one of the value and range input parameters must be given"
151
+ )
152
+ if value is None:
153
+ self._value = [Logic() for _ in range]
154
+ elif isinstance(value, int):
124
155
  if value < 0:
125
156
  bitlen = int.bit_length(value + 1) + 1
126
157
  else: