Skip to content

Commit 95d3f05

Browse files
author
Fernando Governatore
committed
Facilitates sub-classing and user customization by using super()
Using super() instead of hard-coding the class name enables the class to be sub-classed more easily.
1 parent 6adb011 commit 95d3f05

5 files changed

Lines changed: 12 additions & 15 deletions

File tree

barcode/codex.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def build(self):
7171
def render(self, writer_options=None, text=None):
7272
options = {"module_width": MIN_SIZE, "quiet_zone": MIN_QUIET_ZONE}
7373
options.update(writer_options or {})
74-
return Barcode.render(self, options, text)
74+
return super().render(options, text)
7575

7676

7777
class PZN7(Code39):
@@ -98,7 +98,7 @@ def __init__(self, pzn, writer=None):
9898
)
9999
self.pzn = pzn
100100
self.pzn = "{}{}".format(pzn, self.calculate_checksum())
101-
Code39.__init__(self, "PZN-{}".format(self.pzn), writer, add_checksum=False)
101+
super().__init__("PZN-{}".format(self.pzn), writer, add_checksum=False)
102102

103103
def get_fullcode(self):
104104
return "PZN-{}".format(self.pzn)
@@ -248,7 +248,7 @@ def build(self):
248248
def render(self, writer_options=None, text=None):
249249
options = {"module_width": MIN_SIZE, "quiet_zone": MIN_QUIET_ZONE}
250250
options.update(writer_options or {})
251-
return Barcode.render(self, options, text)
251+
return super().render(options, text)
252252

253253

254254
class Gs1_128(Code128):

barcode/ean.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def to_ascii(self):
125125
def render(self, writer_options=None, text=None):
126126
options = {"module_width": SIZES["SC2"]}
127127
options.update(writer_options or {})
128-
return Barcode.render(self, options, text)
128+
return super().render(options, text)
129129

130130

131131
class EuropeanArticleNumber13WithGuard(EuropeanArticleNumber13):
@@ -150,12 +150,12 @@ class JapanArticleNumber(EuropeanArticleNumber13):
150150

151151
valid_country_codes = list(range(450, 460)) + list(range(490, 500))
152152

153-
def __init__(self, jan, writer=None):
154-
if int(jan[:3]) not in JapanArticleNumber.valid_country_codes:
153+
def __init__(self, jan, *args, **kwargs):
154+
if int(jan[:3]) not in self.valid_country_codes:
155155
raise WrongCountryCodeError(
156156
"Country code isn't between 450-460 or 490-500."
157157
)
158-
EuropeanArticleNumber13.__init__(self, jan, writer)
158+
super().__init__(jan, *args, **kwargs)
159159

160160

161161
class EuropeanArticleNumber8(EuropeanArticleNumber13):
@@ -172,9 +172,6 @@ class EuropeanArticleNumber8(EuropeanArticleNumber13):
172172

173173
digits = 7
174174

175-
def __init__(self, ean, writer=None, guardbar=False):
176-
EuropeanArticleNumber13.__init__(self, ean, writer, guardbar=guardbar)
177-
178175
def build(self):
179176
"""Builds the barcode pattern from `self.ean`.
180177

barcode/isxn.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __init__(self, isbn, writer=None):
4848
if isbn[:3] == "979":
4949
if isbn[3:5] not in ("10", "11"):
5050
raise BarcodeError("ISBN must start with 97910 or 97911.")
51-
EuropeanArticleNumber13.__init__(self, isbn, writer)
51+
super().__init__(isbn, writer)
5252

5353

5454
class InternationalStandardBookNumber10(InternationalStandardBookNumber13):
@@ -71,7 +71,7 @@ def __init__(self, isbn, writer=None):
7171
isbn = isbn[: self.digits]
7272
self.isbn10 = isbn
7373
self.isbn10 = "{}{}".format(isbn, self._calculate_checksum())
74-
InternationalStandardBookNumber13.__init__(self, "978" + isbn, writer)
74+
super().__init__("978" + isbn, writer)
7575

7676
def _calculate_checksum(self):
7777
tmp = sum(x * int(y) for x, y in enumerate(self.isbn10[:9], start=1)) % 11
@@ -104,7 +104,7 @@ def __init__(self, issn, writer=None):
104104
issn = issn[: self.digits]
105105
self.issn = issn
106106
self.issn = "{}{}".format(issn, self._calculate_checksum())
107-
EuropeanArticleNumber13.__init__(self, self.make_ean(), writer)
107+
super().__init__(self.make_ean(), writer)
108108

109109
def _calculate_checksum(self):
110110
tmp = (

barcode/itf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@ def render(self, writer_options, text=None):
7373
"quiet_zone": MIN_QUIET_ZONE,
7474
}
7575
options.update(writer_options or {})
76-
return Barcode.render(self, options, text)
76+
return super().render(options, text)

barcode/upc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def to_ascii(self):
108108
def render(self, writer_options=None, text=None):
109109
options = {"module_width": 0.33}
110110
options.update(writer_options or {})
111-
return Barcode.render(self, options, text)
111+
return super().render(options, text)
112112

113113

114114
UPCA = UniversalProductCodeA

0 commit comments

Comments
 (0)