From: whitequark Date: Sat, 15 Dec 2018 09:31:58 +0000 (+0000) Subject: Consistently use '{!r}' in and only in TypeError messages. X-Git-Tag: working~230 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3a8685c3523cdff7c2d684e60e5157f619097ca2;p=nmigen.git Consistently use '{!r}' in and only in TypeError messages. --- diff --git a/nmigen/back/pysim.py b/nmigen/back/pysim.py index 6f13811..6a15b7d 100644 --- a/nmigen/back/pysim.py +++ b/nmigen/back/pysim.py @@ -100,7 +100,7 @@ class _RHSValueCompiler(ValueTransformer): if value.op == "m": sel, val1, val0 = map(self, value.operands) return lambda state: val1(state) if sel(state) else val0(state) - raise NotImplementedError("Operator '{!r}' not implemented".format(value.op)) # :nocov: + raise NotImplementedError("Operator '{}' not implemented".format(value.op)) # :nocov: def on_Slice(self, value): shape = value.shape() diff --git a/nmigen/fhdl/ast.py b/nmigen/fhdl/ast.py index 1908a0e..01a43ba 100644 --- a/nmigen/fhdl/ast.py +++ b/nmigen/fhdl/ast.py @@ -34,7 +34,7 @@ class Value(metaclass=ABCMeta): elif isinstance(obj, (bool, int)): return Const(obj) else: - raise TypeError("Object {!r} is not a Migen value".format(repr(obj))) + raise TypeError("Object '{!r}' is not a Migen value".format(obj)) def __init__(self, src_loc_at=0): super().__init__() @@ -344,9 +344,9 @@ def Mux(sel, val1, val0): class Slice(Value): def __init__(self, value, start, end): if not isinstance(start, int): - raise TypeError("Slice start must be an integer, not {!r}".format(start)) + raise TypeError("Slice start must be an integer, not '{!r}'".format(start)) if not isinstance(end, int): - raise TypeError("Slice end must be an integer, not {!r}".format(end)) + raise TypeError("Slice end must be an integer, not '{!r}'".format(end)) n = len(value) if start not in range(-n, n): @@ -381,7 +381,7 @@ class Slice(Value): class Part(Value): def __init__(self, value, offset, width): if not isinstance(width, int) or width < 0: - raise TypeError("Part width must be a non-negative integer, not {!r}".format(width)) + raise TypeError("Part width must be a non-negative integer, not '{!r}'".format(width)) super().__init__() self.value = value @@ -464,7 +464,7 @@ class Repl(Value): """ def __init__(self, value, count): if not isinstance(count, int) or count < 0: - raise TypeError("Replication count must be a non-negative integer, not {!r}" + raise TypeError("Replication count must be a non-negative integer, not '{!r}'" .format(count)) super().__init__() @@ -544,7 +544,7 @@ class Signal(Value, DUID): max = 2 max -= 1 # make both bounds inclusive if not min < max: - raise ValueError("Lower bound {!r} should be less than higher bound {!r}" + raise ValueError("Lower bound {} should be less than higher bound {}" .format(min, max)) self.signed = min < 0 or max < 0 self.nbits = builtins.max(bits_for(min, self.signed), bits_for(max, self.signed)) @@ -558,7 +558,7 @@ class Signal(Value, DUID): self.nbits, self.signed = shape if not isinstance(self.nbits, int) or self.nbits < 0: - raise TypeError("Width must be a non-negative integer, not {!r}".format(self.nbits)) + raise TypeError("Width must be a non-negative integer, not '{!r}'".format(self.nbits)) self.reset = int(reset) self.reset_less = bool(reset_less) @@ -609,7 +609,7 @@ class ClockSignal(Value): def __init__(self, domain="sync"): super().__init__() if not isinstance(domain, str): - raise TypeError("Clock domain name must be a string, not {!r}".format(domain)) + raise TypeError("Clock domain name must be a string, not '{!r}'".format(domain)) self.domain = domain def shape(self): @@ -638,7 +638,7 @@ class ResetSignal(Value): def __init__(self, domain="sync", allow_reset_less=False): super().__init__() if not isinstance(domain, str): - raise TypeError("Clock domain name must be a string, not {!r}".format(domain)) + raise TypeError("Clock domain name must be a string, not '{!r}'".format(domain)) self.domain = domain self.allow_reset_less = allow_reset_less @@ -666,7 +666,7 @@ class Statement: if isinstance(obj, Statement): return _StatementList([obj]) else: - raise TypeError("Object {!r} is not a Migen statement".format(obj)) + raise TypeError("Object '{!r}' is not a Migen statement".format(obj)) class Assign(Statement): @@ -694,7 +694,7 @@ class Switch(Statement): elif isinstance(key, str): assert len(key) == len(self.test) else: - raise TypeError("Object {!r} cannot be used as a switch key" + raise TypeError("Object '{!r}' cannot be used as a switch key" .format(key)) if not isinstance(stmts, Iterable): stmts = [stmts] @@ -759,7 +759,7 @@ class ValueKey: elif isinstance(self.value, Slice): return hash((ValueKey(self.value.value), self.value.start, self.value.end)) else: # :nocov: - raise TypeError("Object {!r} cannot be used as a key in value collections") + raise TypeError("Object '{!r}' cannot be used as a key in value collections") def __eq__(self, other): if not isinstance(other, ValueKey): @@ -776,7 +776,7 @@ class ValueKey: self.value.start == other.value.start and self.value.end == other.value.end) else: # :nocov: - raise TypeError("Object {!r} cannot be used as a key in value collections") + raise TypeError("Object '{!r}' cannot be used as a key in value collections") def __lt__(self, other): if not isinstance(other, ValueKey): @@ -793,7 +793,7 @@ class ValueKey: self.value.start < other.value.start and self.value.end < other.value.end) else: # :nocov: - raise TypeError("Object {!r} cannot be used as a key in value collections") + raise TypeError("Object '{!r}' cannot be used as a key in value collections") def __repr__(self): return "<{}.ValueKey {!r}>".format(__name__, self.value) diff --git a/nmigen/fhdl/xfrm.py b/nmigen/fhdl/xfrm.py index 35699f1..1ef3275 100644 --- a/nmigen/fhdl/xfrm.py +++ b/nmigen/fhdl/xfrm.py @@ -41,7 +41,7 @@ class ValueTransformer: return Repl(self.on_value(value.value), value.count) def on_unknown_value(self, value): - raise TypeError("Cannot transform value {!r}".format(value)) # :nocov: + raise TypeError("Cannot transform value '{!r}'".format(value)) # :nocov: def on_value(self, value): if isinstance(value, Const): @@ -87,7 +87,7 @@ class StatementTransformer: return _StatementList(flatten(self.on_statement(stmt) for stmt in stmt)) def on_unknown_statement(self, stmt): - raise TypeError("Cannot transform statement {!r}".format(stmt)) # :nocov: + raise TypeError("Cannot transform statement '{!r}'".format(stmt)) # :nocov: def on_statement(self, stmt): if isinstance(stmt, Assign):