Skip to content

Commit 962754e

Browse files
author
Hugo Osvaldo Barrera
committed
Run pyupgrade
1 parent 564b13b commit 962754e

9 files changed

Lines changed: 20 additions & 22 deletions

File tree

barcode/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ def get(name, code=None, writer=None, options=None):
6969
try:
7070
barcode = __BARCODE_MAP[name.lower()]
7171
except KeyError:
72-
raise BarcodeNotFoundError(
73-
"The barcode {!r} you requested is not known.".format(name)
74-
)
72+
raise BarcodeNotFoundError(f"The barcode {name!r} you requested is not known.")
7573
if code is not None:
7674
return barcode(code, writer, **options)
7775
else:

barcode/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def to_ascii(self):
3131
return "\n".join(code)
3232

3333
def __repr__(self):
34-
return "<{}({!r})>".format(self.__class__.__name__, self.get_fullcode())
34+
return f"<{self.__class__.__name__}({self.get_fullcode()!r})>"
3535

3636
def build(self):
3737
raise NotImplementedError

barcode/codex.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ def __init__(self, pzn, writer=None):
9494
raise IllegalCharacterError("PZN can only contain numbers.")
9595
if len(pzn) != self.digits:
9696
raise NumberOfDigitsError(
97-
"PZN must have {} digits, not {}.".format(self.digits, len(pzn))
97+
f"PZN must have {self.digits} digits, not {len(pzn)}."
9898
)
9999
self.pzn = pzn
100-
self.pzn = "{}{}".format(pzn, self.calculate_checksum())
101-
super().__init__("PZN-{}".format(self.pzn), writer, add_checksum=False)
100+
self.pzn = f"{pzn}{self.calculate_checksum()}"
101+
super().__init__(f"PZN-{self.pzn}", writer, add_checksum=False)
102102

103103
def get_fullcode(self):
104-
return "PZN-{}".format(self.pzn)
104+
return f"PZN-{self.pzn}"
105105

106106
def calculate_checksum(self):
107107
sum_ = sum(int(x) * int(y) for x, y in enumerate(self.pzn, start=2))

barcode/ean.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __init__(self, ean, writer=None, no_checksum=False, guardbar=False):
6161
ean, ean[self.digits] if len(ean) > self.digits else 0
6262
)
6363
else:
64-
self.ean = "{}{}".format(ean, self.calculate_checksum())
64+
self.ean = f"{ean}{self.calculate_checksum()}"
6565

6666
self.guardbar = guardbar
6767
if guardbar:

barcode/isxn.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def __init__(self, isbn, writer=None):
7070
isbn = isbn.replace("-", "")
7171
isbn = isbn[: self.digits]
7272
self.isbn10 = isbn
73-
self.isbn10 = "{}{}".format(isbn, self._calculate_checksum())
73+
self.isbn10 = f"{isbn}{self._calculate_checksum()}"
7474
super().__init__("978" + isbn, writer)
7575

7676
def _calculate_checksum(self):
@@ -103,7 +103,7 @@ def __init__(self, issn, writer=None):
103103
issn = issn.replace("-", "")
104104
issn = issn[: self.digits]
105105
self.issn = issn
106-
self.issn = "{}{}".format(issn, self._calculate_checksum())
106+
self.issn = f"{issn}{self._calculate_checksum()}"
107107
super().__init__(self.make_ean(), writer)
108108

109109
def _calculate_checksum(self):
@@ -118,7 +118,7 @@ def _calculate_checksum(self):
118118
return tmp
119119

120120
def make_ean(self):
121-
return "977{}00{}".format(self.issn[:7], self._calculate_checksum())
121+
return f"977{self.issn[:7]}00{self._calculate_checksum()}"
122122

123123
def __str__(self):
124124
return self.issn

barcode/pybarcode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def create_barcode(args, parser):
4545
writer = SVGWriter()
4646
out = os.path.normpath(os.path.abspath(args.output))
4747
name = barcode.generate(args.barcode, args.code, writer, out, opts, args.text)
48-
print("New barcode saved as {}.".format(name))
48+
print(f"New barcode saved as {name}.")
4949

5050

5151
def main():

barcode/upc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ def __init__(self, upc, writer=None, make_ean=False):
3838
raise IllegalCharacterError("UPC code can only contain numbers.")
3939
if len(upc) != self.digits:
4040
raise NumberOfDigitsError(
41-
"UPC must have {} digits, not {}.".format(self.digits, len(upc))
41+
f"UPC must have {self.digits} digits, not {len(upc)}."
4242
)
4343
self.upc = upc
44-
self.upc = "{}{}".format(upc, self.calculate_checksum())
44+
self.upc = f"{upc}{self.calculate_checksum()}"
4545
self.writer = writer or self.default_writer()
4646

4747
def __str__(self):

barcode/writer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def create_svg_object(with_doctype=False):
5050

5151

5252
SIZE = "{0:.3f}mm"
53-
COMMENT = "Autogenerated with python-barcode {}".format(version)
53+
COMMENT = f"Autogenerated with python-barcode {version}"
5454
PATH = os.path.dirname(os.path.abspath(__file__))
5555

5656

@@ -322,7 +322,7 @@ def _init(self, code):
322322
attributes = {
323323
"width": "100%",
324324
"height": "100%",
325-
"style": "fill:{}".format(self.background),
325+
"style": f"fill:{self.background}",
326326
}
327327
_set_attributes(background, **attributes)
328328
self._group.appendChild(background)
@@ -334,7 +334,7 @@ def _create_module(self, xpos, ypos, width, color):
334334
"y": SIZE.format(ypos),
335335
"width": SIZE.format(width),
336336
"height": SIZE.format(self.module_height),
337-
"style": "fill:{};".format(color),
337+
"style": f"fill:{color};",
338338
}
339339
_set_attributes(element, **attributes)
340340
self._group.appendChild(element)
@@ -372,12 +372,12 @@ def _finish(self):
372372

373373
def save(self, filename, output):
374374
if self.compress:
375-
_filename = "{}.svgz".format(filename)
375+
_filename = f"{filename}.svgz"
376376
f = gzip.open(_filename, "wb")
377377
f.write(output)
378378
f.close()
379379
else:
380-
_filename = "{}.svg".format(filename)
380+
_filename = f"{filename}.svg"
381381
with open(_filename, "wb") as f:
382382
f.write(output)
383383
return _filename
@@ -449,7 +449,7 @@ def _finish(self):
449449
return self._image
450450

451451
def save(self, filename, output):
452-
filename = "{}.{}".format(filename, self.format.lower())
452+
filename = f"{filename}.{self.format.lower()}"
453453
output.save(filename, self.format.upper())
454454
return filename
455455

tests/test_manually.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@ def append_img(x, y):
9090
obj = "\n".join(objects)
9191
f.write(HTML.format(version=version, body=obj))
9292

93-
print("\nNow open {htmlfile} in your browser.".format(htmlfile=HTMLFILE))
93+
print(f"\nNow open {HTMLFILE} in your browser.")

0 commit comments

Comments
 (0)