Skip to content

Commit d674512

Browse files
committed
ruff: Enable and autofix some extra rules
1 parent 3974cb7 commit d674512

6 files changed

Lines changed: 18 additions & 27 deletions

File tree

barcode/base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ def save(self, filename, options=None, text=None):
5959
:returns: The full filename with extension.
6060
:rtype: String
6161
"""
62-
if text:
63-
output = self.render(options, text)
64-
else:
65-
output = self.render(options)
62+
output = self.render(options, text) if text else self.render(options)
6663

6764
_filename = self.writer.save(filename, output)
6865
return _filename

barcode/codex.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,13 @@ def look_next():
183183
elif self._charset == "B":
184184
if look_next():
185185
codes = self._new_charset("C")
186-
elif char not in code128.B:
187-
if char in code128.A:
188-
codes = self._new_charset("A")
186+
elif char not in code128.B and char in code128.A:
187+
codes = self._new_charset("A")
189188
elif self._charset == "A":
190189
if look_next():
191190
codes = self._new_charset("C")
192-
elif char not in code128.A:
193-
if char in code128.B:
194-
codes = self._new_charset("B")
191+
elif char not in code128.A and char in code128.B:
192+
codes = self._new_charset("B")
195193
return codes
196194

197195
def _convert(self, char):

barcode/isxn.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ def __init__(self, isbn, writer=None):
4545
self.isbn13 = isbn
4646
if isbn[:3] not in ("978", "979"):
4747
raise WrongCountryCodeError("ISBN must start with 978 or 979.")
48-
if isbn[:3] == "979":
49-
if isbn[3:5] not in ("10", "11"):
50-
raise BarcodeError("ISBN must start with 97910 or 97911.")
48+
if isbn[:3] == "979" and isbn[3:5] not in ("10", "11"):
49+
raise BarcodeError("ISBN must start with 97910 or 97911.")
5150
super().__init__(isbn, writer)
5251

5352

barcode/writer.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,7 @@ def _create_module(self, xpos, ypos, width, color):
348348
def _create_text(self, xpos, ypos):
349349
# check option to override self.text with self.human (barcode as
350350
# human readable data, can be used to print own formats)
351-
if self.human != "":
352-
barcodetext = self.human
353-
else:
354-
barcodetext = self.text
351+
barcodetext = self.human if self.human != "" else self.text
355352
for subtext in barcodetext.split("\n"):
356353
element = self._document.createElement("text")
357354
attributes = {

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ select = [
1919
# "N",
2020
"C4",
2121
"PT",
22-
# "SIM",
22+
"SIM",
2323
"TID",
2424
]
2525
target-version = "py37"

tests/test_checksums.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,44 @@
33

44
def test_code39_checksum():
55
code39 = get_barcode("code39", "Code39")
6-
assert "CODE39W" == code39.get_fullcode()
6+
assert code39.get_fullcode() == "CODE39W"
77

88

99
def test_pzn_checksum():
1010
pzn = get_barcode("pzn", "103940")
11-
assert "PZN-1039406" == pzn.get_fullcode()
11+
assert pzn.get_fullcode() == "PZN-1039406"
1212

1313

1414
def test_ean13_checksum():
1515
ean = get_barcode("ean13", "400614457735")
16-
assert "4006144577350" == ean.get_fullcode()
16+
assert ean.get_fullcode() == "4006144577350"
1717

1818

1919
def test_ean8_checksum():
2020
ean = get_barcode("ean8", "6032299")
21-
assert "60322999" == ean.get_fullcode()
21+
assert ean.get_fullcode() == "60322999"
2222

2323

2424
def test_jan_checksum():
2525
jan = get_barcode("jan", "491400614457")
26-
assert "4914006144575" == jan.get_fullcode()
26+
assert jan.get_fullcode() == "4914006144575"
2727

2828

2929
def test_ean14_checksum():
3030
ean = get_barcode("ean14", "1234567891258")
31-
assert "12345678912589" == ean.get_fullcode()
31+
assert ean.get_fullcode() == "12345678912589"
3232

3333

3434
def test_isbn10_checksum():
3535
isbn = get_barcode("isbn10", "376926085")
36-
assert "3769260856" == isbn.isbn10
36+
assert isbn.isbn10 == "3769260856"
3737

3838

3939
def test_isbn13_checksum():
4040
isbn = get_barcode("isbn13", "978376926085")
41-
assert "9783769260854" == isbn.get_fullcode()
41+
assert isbn.get_fullcode() == "9783769260854"
4242

4343

4444
def test_gs1_128_checksum():
4545
gs1_128 = get_barcode("gs1_128", "00376401856400470087")
46-
assert "00376401856400470087" == gs1_128.get_fullcode()
46+
assert gs1_128.get_fullcode() == "00376401856400470087"

0 commit comments

Comments
 (0)