Skip to content

Commit 2096319

Browse files
committed
Revert EM101 102
1 parent f6e1715 commit 2096319

File tree

11 files changed

+35
-48
lines changed

11 files changed

+35
-48
lines changed

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ lint.ignore = [
111111
"ARG005", # Unused lambda argument
112112
"D", # Missing or badly formatted docstrings
113113
"E501", # Line too long (>88)
114+
"EM101", # Exception must not use a string literal, assign to variable first
115+
"EM102", # Exception must not use an f-string literal, assign to variable first "ERA001", # Found commented-out code
114116
"ERA001", # Found commented-out code
115117
"FBT", # Flake Boolean Trap (don't use arg=True in functions)
116118
"N999", # Invalid module name
@@ -119,6 +121,7 @@ lint.ignore = [
119121
"RUF012", # Mutable class attributes https://github.com/astral-sh/ruff/issues/5243
120122
"SIM105", # Use contextlib.suppress(ImportError) instead of try-except-pass
121123
"SLF001", # private-member-access
124+
"TRY003", # Avoid specifying long messages outside the exception class
122125

123126
# Should be fixed later
124127
"C901", # Too complex

qrcode/base.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,7 @@
234234

235235
def glog(n):
236236
if n < 1: # pragma: no cover
237-
msg = f"glog({n})"
238-
raise ValueError(msg)
237+
raise ValueError(f"glog({n})")
239238
return LOG_TABLE[n]
240239

241240

@@ -246,8 +245,7 @@ def gexp(n):
246245
class Polynomial:
247246
def __init__(self, num, shift):
248247
if not num: # pragma: no cover
249-
msg = f"{len(num)}/{shift}"
250-
raise ValueError(msg)
248+
raise ValueError(f"{len(num)}/{shift}")
251249

252250
offset = 0
253251
for offset in range(len(num)):
@@ -299,10 +297,9 @@ class RSBlock(NamedTuple):
299297

300298
def rs_blocks(version, error_correction):
301299
if error_correction not in RS_BLOCK_OFFSET: # pragma: no cover
302-
msg = (
300+
raise ValueError(
303301
f"bad rs block @ version: {version} / error_correction: {error_correction}"
304302
)
305-
raise ValueError(msg)
306303
offset = RS_BLOCK_OFFSET[error_correction]
307304
rs_block = RS_BLOCK_TABLE[(version - 1) * 4 + offset]
308305

qrcode/console_scripts.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ def raise_error(msg: str) -> NoReturn:
149149

150150
def get_factory(module: str) -> type[BaseImage]:
151151
if "." not in module:
152-
msg = "The image factory is not a full python path"
153-
raise ValueError(msg)
152+
raise ValueError("The image factory is not a full python path")
154153
module, name = module.rsplit(".", 1)
155154
imp = __import__(module, {}, {}, [name])
156155
return getattr(imp, name)

qrcode/image/base.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,13 @@ def drawrect_context(self, row: int, col: int, qr: QRCode):
4242
"""
4343
Draw a single rectangle of the QR code given the surrounding context
4444
"""
45-
msg = "BaseImage.drawrect_context"
46-
raise NotImplementedError(msg) # pragma: no cover
45+
raise NotImplementedError("BaseImage.drawrect_context") # pragma: no cover
4746

4847
def process(self):
4948
"""
5049
Processes QR code after completion
5150
"""
52-
msg = "BaseImage.drawimage"
53-
raise NotImplementedError(msg) # pragma: no cover
51+
raise NotImplementedError("BaseImage.drawimage") # pragma: no cover
5452

5553
@abc.abstractmethod
5654
def save(self, stream, kind=None):
@@ -97,8 +95,7 @@ def check_kind(self, kind, transform=None):
9795
if not allowed:
9896
allowed = kind in self.allowed_kinds
9997
if not allowed:
100-
msg = f"Cannot set {type(self).__name__} type to {kind}"
101-
raise ValueError(msg)
98+
raise ValueError(f"Cannot set {type(self).__name__} type to {kind}")
10299
return kind
103100

104101
def is_eye(self, row: int, col: int):

qrcode/image/pil.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ class PilImage(qrcode.image.base.BaseImage):
1414

1515
def new_image(self, **kwargs):
1616
if not Image:
17-
msg = "PIL library not found."
18-
raise ImportError(msg)
17+
raise ImportError("PIL library not found.")
1918

2019
back_color = kwargs.get("back_color", "white")
2120
fill_color = kwargs.get("fill_color", "black")

qrcode/image/pure.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ class PyPNGImage(BaseImage):
1616

1717
def new_image(self, **kwargs):
1818
if not PngWriter:
19-
msg = "PyPNG library not installed."
20-
raise ImportError(msg)
19+
raise ImportError("PyPNG library not installed.")
2120

2221
return PngWriter(self.pixel_size, self.pixel_size, greyscale=True, bitdepth=1)
2322

qrcode/image/styles/colormasks.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ def apply_mask(self, image, use_cache=False):
5656
pixels[x, y] = self.get_bg_pixel(image, x, y)
5757

5858
def get_fg_pixel(self, image, x, y):
59-
msg = "QRModuleDrawer.paint_fg_pixel"
60-
raise NotImplementedError(msg)
59+
raise NotImplementedError("QRModuleDrawer.paint_fg_pixel")
6160

6261
def get_bg_pixel(self, image, x, y):
6362
return self.back_color

qrcode/image/styles/moduledrawers/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,4 @@ def __getattr__(name):
4343
return getattr(pil, name)
4444

4545
# For any other attribute, raise AttributeError
46-
msg = f"module {__name__!r} has no attribute {name!r}"
47-
raise AttributeError(msg)
46+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

qrcode/main.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@ def make(data=None, **kwargs):
2222

2323
def _check_box_size(size):
2424
if int(size) <= 0:
25-
msg = f"Invalid box size (was {size}, expected larger than 0)"
26-
raise ValueError(msg)
25+
raise ValueError(f"Invalid box size (was {size}, expected larger than 0)")
2726

2827

2928
def _check_border(size):
3029
if int(size) < 0:
31-
msg = f"Invalid border value (was {size}, expected 0 or larger than that)"
32-
raise ValueError(msg)
30+
raise ValueError(
31+
f"Invalid border value (was {size}, expected 0 or larger than that)"
32+
)
3333

3434

3535
def _check_mask_pattern(mask_pattern):
3636
if mask_pattern is None:
3737
return
3838
if not isinstance(mask_pattern, int):
39-
msg = f"Invalid mask pattern (was {type(mask_pattern)}, expected int)"
40-
raise TypeError(msg)
39+
raise TypeError(
40+
f"Invalid mask pattern (was {type(mask_pattern)}, expected int)"
41+
)
4142
if mask_pattern < 0 or mask_pattern > 7:
42-
msg = f"Mask pattern should be in range(8) (got {mask_pattern})"
43-
raise ValueError(msg)
43+
raise ValueError(f"Mask pattern should be in range(8) (got {mask_pattern})")
4444

4545

4646
def copy_2d_array(x):
@@ -258,8 +258,7 @@ def print_tty(self, out=None):
258258
out = sys.stdout
259259

260260
if not out.isatty():
261-
msg = "Not a tty"
262-
raise OSError(msg)
261+
raise OSError("Not a tty")
263262

264263
if self.data_cache is None:
265264
self.make()
@@ -288,8 +287,7 @@ def print_ascii(self, out=None, tty=False, invert=False):
288287
out = sys.stdout
289288

290289
if tty and not out.isatty():
291-
msg = "Not a tty"
292-
raise OSError(msg)
290+
raise OSError("Not a tty")
293291

294292
if self.data_cache is None:
295293
self.make()
@@ -354,8 +352,9 @@ def make_image(self, image_factory=None, **kwargs):
354352
or kwargs.get("embeded_image_path")
355353
or kwargs.get("embeded_image")
356354
) and self.error_correction != constants.ERROR_CORRECT_H:
357-
msg = "Error correction level must be ERROR_CORRECT_H if an embedded image is provided"
358-
raise ValueError(msg)
355+
raise ValueError(
356+
"Error correction level must be ERROR_CORRECT_H if an embedded image is provided"
357+
)
359358

360359
_check_box_size(self.box_size)
361360
if self.data_cache is None:

qrcode/tests/test_script.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88

99
def bad_read():
10-
msg = "utf-8"
11-
raise UnicodeDecodeError(msg, b"0x80", 0, 1, "invalid start byte")
10+
raise UnicodeDecodeError("utf-8", b"0x80", 0, 1, "invalid start byte")
1211

1312

1413
@mock.patch("os.isatty", return_value=True)

0 commit comments

Comments
 (0)