Commit 50f9ab78 authored by Sean Leavey's avatar Sean Leavey

Replace most format strings with f-strings

parent 04db3912
Pipeline #68691 passed with stage
in 10 minutes and 55 seconds
......@@ -384,12 +384,12 @@ class Circuit:
count = 1
# first attempt
new_name = "{base}{count}".format(base=base, count=count)
new_name = f"{base}{count}"
while new_name in self.component_names:
# next attempt
count += 1
new_name = "{base}{count}".format(base=base, count=count)
new_name = f"{base}{count}"
# set new name
component.name = new_name
......
......@@ -353,7 +353,7 @@ class OpAmp(LibraryOpAmp, Component):
raise NoiseNotFoundError("inverting current noise")
def __str__(self):
suffix = " [in+={cmp.node1}, in-={cmp.node2}, out={cmp.node3}, model={cmp.model}]".format(cmp=self)
suffix = f" [in+={self.node1}, in-={self.node2}, out={self.node3}, model={self.model}]"
return Component.__str__(self) + suffix
......@@ -419,8 +419,7 @@ class Input(Component):
z = self.impedance
else:
z = "default"
return super().__str__() + " [in={cmp.node1}, out={cmp.node2}, Z={z}]".format(cmp=self, z=z)
return super().__str__() + f" [in={self.node1}, out={self.node2}, Z={z}]"
class Resistor(PassiveComponent):
......@@ -463,7 +462,7 @@ class Resistor(PassiveComponent):
raise ValueError("no Johnson noise")
def __str__(self):
return super().__str__() + " [in={cmp.node1}, out={cmp.node2}, R={cmp.resistance}]".format(cmp=self)
return super().__str__() + f" [in={self.node1}, out={self.node2}, R={self.resistance}]"
class Capacitor(PassiveComponent):
......@@ -496,7 +495,7 @@ class Capacitor(PassiveComponent):
return 1 / (2j * np.pi * frequency * self.capacitance)
def __str__(self):
return super().__str__() + " [in={cmp.node1}, out={cmp.node2}, C={cmp.capacitance}]".format(cmp=self)
return super().__str__() + f" [in={self.node1}, out={self.node2}, C={self.capacitance}]"
class Inductor(PassiveComponent):
......@@ -584,7 +583,7 @@ class Inductor(PassiveComponent):
return self.coupling_factors.keys()
def __str__(self):
return super().__str__() + " [in={cmp.node1}, out={cmp.node2}, L={cmp.inductance}]".format(cmp=self)
return super().__str__() + f" [in={self.node1}, out={self.node2}, L={self.inductance}]"
class ComponentNotFoundError(ElementNotFoundError):
......
......@@ -465,4 +465,4 @@ class LibraryOpAmp:
return pairs
def __str__(self):
return "{cmp.model}(a0={cmp.a0}, gbw={cmp.gbw}, delay={cmp.delay})".format(cmp=self)
return f"{self.model}(a0={self.a0}, gbw={self.gbw}, delay={self.delay})"
......@@ -229,14 +229,13 @@ class LibraryParserError(ValueError):
pos = int(pos)
# add line number and position
message = "{message} (line {line}, position {pos})".format(message=message,
line=line, pos=pos)
message = f"{message} (line {line}, position {pos})"
else:
# add line number
message = "{message} (line {line})".format(message=message, line=line)
message = f"{message} (line {line})"
# prepend message
message = "Syntax error: {message}".format(message=message)
message = f"Syntax error: {message}"
super().__init__(message, **kwargs)
......
......@@ -64,7 +64,7 @@ class Part:
return next(iter(self.sorted_datasheets), None)
def __repr__(self):
return "{brand} / {manufacturer} {mpn}".format(**self.__dict__)
return f"{self.brand} / {self.manufacturer} {self.mpn}"
class Datasheet(Downloadable):
......
......@@ -58,11 +58,18 @@ class NodeGraph:
if isinstance(component, OpAmp):
attr = {'shape': 'plain', 'margin': '0', 'orientation': '270'}
attr['label'] = """<<TABLE BORDER="0" BGCOLOR="LightSkyBlue">
<TR><TD PORT="plus">+</TD><TD ROWSPAN="3">{0}<BR/>{1}</TD></TR>
<TR><TD> </TD></TR>
<TR><TD PORT="minus">-</TD></TR>
</TABLE>>""".format(component.name, component.model)
attr['label'] = f"""<<TABLE BORDER="0" BGCOLOR="LightSkyBlue">
<TR>
<TD PORT="plus">+</TD>
<TD ROWSPAN="3">{component.name}<BR/>{component.model}</TD>
</TR>
<TR>
<TD> </TD>
</TR>
<TR>
<TD PORT="minus">-</TD>
</TR>
</TABLE>>"""
connections = [':plus', ':minus', ':e']
elif isinstance(component, Inductor):
attr = {'fillcolor': 'MediumSlateBlue', 'shape': 'diamond'}
......
......@@ -27,14 +27,13 @@ class LisoParserError(ValueError):
pos = int(pos)
# add line number and position
message = "{message} (line {line}, position {pos})".format(message=message,
line=line, pos=pos)
message = f"{message} (line {line}, position {pos})"
else:
# add line number
message = "{message} (line {line})".format(message=message, line=line)
message = f"{message} (line {line})"
# prepend message
message = "LISO syntax error: {message}".format(message=message)
message = f"LISO syntax error: {message}"
super().__init__(message, **kwargs)
......@@ -236,7 +235,7 @@ class LisoParser(metaclass=abc.ABCMeta):
raise ValueError("cannot specify both text and a file to parse")
if not os.path.isfile(path):
raise FileNotFoundError("cannot read '{path}'".format(path=path))
raise FileNotFoundError(f"cannot read '{path}'")
with open(path, "r") as obj:
text = obj.read()
......@@ -250,9 +249,7 @@ class LisoParser(metaclass=abc.ABCMeta):
def t_error(self, t):
# anything that gets past the other filters
pos = t.lexer.lexpos - self._previous_newline_position
raise LisoParserError("illegal character '{char}'".format(char=t.value[0]), self.lineno,
pos)
raise LisoParserError(f"illegal character '{t.value[0]}'", self.lineno, pos)
@abc.abstractmethod
def p_error(self, p):
......
......@@ -403,7 +403,7 @@ class LisoInputParser(LisoParser):
self.p_error("op-amp parameter override must be in the form 'param=value'")
if key not in self.OP_OVERRIDE_MAP.keys():
self.p_error("unknown op-amp override parameter '{key}'".format(key=key))
self.p_error(f"unknown op-amp override parameter '{key}'")
extra_args[self.OP_OVERRIDE_MAP[key]] = value
......
......@@ -840,7 +840,7 @@ class LisoOutputParser(LisoParser):
kwargs["zeros"].extend(self._parse_opamp_root(frequency, plane))
else:
self.p_error("unknown op-amp override parameter '{key}'".format(key=prop))
self.p_error(f"unknown op-amp override parameter '{prop}'")
self.circuit.add_opamp(name=name, model=model, node1=node1, node2=node2, node3=node3,
**kwargs)
......@@ -892,7 +892,7 @@ class LisoOutputParser(LisoParser):
try:
self.add_response_output(sink)
except ValueError:
self.p_error("voltage output '{sink}' already specified".format(sink=sink))
self.p_error(f"voltage output '{sink}' already specified")
def _parse_current_output(self, output):
self._add_current_output(output)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment