Skip to content

Commit 8cdefd7

Browse files
committed
Tidy up some superfluous code
1 parent c937ce9 commit 8cdefd7

7 files changed

Lines changed: 32 additions & 28 deletions

File tree

barcode/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def get(name, code=None, writer=None, options=None):
7575
raise BarcodeNotFoundError(f"The barcode {name!r} is not known.") from e
7676
if code is not None:
7777
return barcode(code, writer, **options)
78-
else:
79-
return barcode
78+
79+
return barcode
8080

8181

8282
def get_class(name):
@@ -111,10 +111,11 @@ def generate(
111111
if isinstance(output, str):
112112
fullname = barcode.save(output, writer_options, text)
113113
return fullname
114-
elif output:
114+
if output:
115115
barcode.write(output, writer_options, text)
116-
else:
117-
raise TypeError("'output' cannot be None")
116+
return None
117+
118+
raise TypeError("'output' cannot be None")
118119

119120

120121
get_barcode = get

barcode/base.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ def save(self, filename, options=None, text=None):
6060
"""
6161
output = self.render(options, text) if text else self.render(options)
6262

63-
_filename = self.writer.save(filename, output)
64-
return _filename
63+
return self.writer.save(filename, output)
6564

6665
def write(self, fp, options=None, text=None):
6766
"""Renders the barcode and writes it to the file like object
@@ -98,5 +97,4 @@ def render(self, writer_options=None, text=None):
9897
options["text"] = self.get_fullcode()
9998
self.writer.set_options(options)
10099
code = self.build()
101-
raw = self.writer.render(code)
102-
return raw
100+
return self.writer.render(code)

barcode/codex.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def calculate_checksum(self):
6060
for k, v in code39.MAP.items():
6161
if check == v[0]:
6262
return k
63+
return None
6364

6465
def build(self):
6566
chars = [code39.EDGE]
@@ -108,8 +109,8 @@ def calculate_checksum(self):
108109
checksum = sum_ % 11
109110
if checksum == 10:
110111
raise BarcodeError("Checksum can not be 10 for PZN.")
111-
else:
112-
return checksum
112+
113+
return checksum
113114

114115

115116
class PZN8(PZN7):
@@ -195,17 +196,20 @@ def look_next():
195196
def _convert(self, char):
196197
if self._charset == "A":
197198
return code128.A[char]
198-
elif self._charset == "B":
199+
if self._charset == "B":
199200
return code128.B[char]
200-
elif self._charset == "C":
201+
if self._charset == "C":
201202
if char in code128.C:
202203
return code128.C[char]
203-
elif char.isdigit():
204+
if char.isdigit():
204205
self._buffer += char
205206
if len(self._buffer) == 2:
206207
value = int(self._buffer)
207208
self._buffer = ""
208209
return value
210+
return None
211+
return None
212+
return None
209213

210214
def _try_to_optimize(self, encoded):
211215
if encoded[1] in code128.TO:

barcode/isxn.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ def _calculate_checksum(self):
7676
tmp = sum(x * int(y) for x, y in enumerate(self.isbn10[:9], start=1)) % 11
7777
if tmp == 10:
7878
return "X"
79-
else:
80-
return tmp
79+
80+
return tmp
8181

8282
def __str__(self):
8383
return self.isbn10
@@ -113,8 +113,8 @@ def _calculate_checksum(self):
113113
)
114114
if tmp == 10:
115115
return "X"
116-
else:
117-
return tmp
116+
117+
return tmp
118118

119119
def make_ean(self):
120120
return f"977{self.issn[:7]}00{self._calculate_checksum()}"

barcode/upc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ def __init__(self, upc, writer=None, make_ean=False):
4747
def __str__(self):
4848
if self.ean:
4949
return "0" + self.upc
50-
else:
51-
return self.upc
50+
51+
return self.upc
5252

5353
def get_fullcode(self):
5454
if self.ean:
5555
return "0" + self.upc
56-
else:
57-
return self.upc
56+
57+
return self.upc
5858

5959
def calculate_checksum(self):
6060
"""Calculates the checksum for UPCA/UPC codes
@@ -72,8 +72,8 @@ def sum_(x, y):
7272
check = (evensum + oddsum * 3) % 10
7373
if check == 0:
7474
return 0
75-
else:
76-
return 10 - check
75+
76+
return 10 - check
7777

7878
def build(self):
7979
"""Builds the barcode pattern from 'self.upc'

barcode/writer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,10 @@ def _create_text(self, xpos, ypos):
364364
def _finish(self):
365365
if self.compress:
366366
return self._document.toxml(encoding="UTF-8")
367-
else:
368-
return self._document.toprettyxml(
369-
indent=4 * " ", newl=os.linesep, encoding="UTF-8"
370-
)
367+
368+
return self._document.toprettyxml(
369+
indent=4 * " ", newl=os.linesep, encoding="UTF-8"
370+
)
371371

372372
def save(self, filename, output):
373373
if self.compress:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ select = [
2828
"PT",
2929
"Q",
3030
"RSE",
31+
"RET",
3132
"SIM",
3233
"TID",
3334
"TCH",

0 commit comments

Comments
 (0)