Skip to content

Commit

Permalink
better exception on VcdVarIdScope.registerVariable faulire
Browse files Browse the repository at this point in the history
  • Loading branch information
Nic30 committed Jul 16, 2018
1 parent abaf21f commit effe557
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pyDigitalWaveTools/vcd/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from typing import Callable
from pyDigitalWaveTools.vcd.common import VcdVarScope, VCD_SIG_TYPE, VcdVarInfo

class VarAlreadyRegistered(Exception):
pass

class VcdVarWritingInfo(VcdVarInfo):
"""
Expand Down Expand Up @@ -52,7 +54,7 @@ def registerVariable(self, sig: object, name: str, parent: VcdVarScope,
valueFormatter: Callable[["Value"], str]):
varId = self._idToStr(self._nextId)
if sig is not None and sig in self:
raise KeyError("%r is already registered" % (sig))
raise VarAlreadyRegistered("%r is already registered" % (sig))
vInf = VcdVarWritingInfo(
varId, name, width, sigType, parent, valueFormatter)
self[sig] = vInf
Expand Down Expand Up @@ -92,9 +94,10 @@ def varScope(self, name):
"""
Create sub variable scope with defined name
"""
ch = VcdVarWritingScope(name, self.writer, parent=self)
ch = VcdVarWritingScope(name, self._writer, parent=self)
assert name not in self.children, name
self.children[name] = ch
return ch

def __enter__(self) -> "VcdVarWritingScope":
self._writeHeader()
Expand Down

0 comments on commit effe557

Please sign in to comment.