Skip to content

Commit bae2564

Browse files
authored
Merge pull request #150 from maresb/chore/ruff-infer-target
Infer Ruff target-version from requires-python
2 parents b9554e3 + 4cf7533 commit bae2564

12 files changed

Lines changed: 55 additions & 64 deletions

File tree

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ drop = [
181181
line-length = 88
182182
extend-exclude = ["_vendor"]
183183
src = ["src"]
184-
target-version = "py38"
185184

186185
[tool.ruff.lint]
187186
select = [

src/labelle/cli/cli.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import logging
99
import sys
1010
from pathlib import Path
11-
from typing import Annotated, List, NoReturn, Optional
11+
from typing import Annotated, NoReturn
1212

1313
import typer
1414
from rich.console import Console
@@ -109,7 +109,7 @@ def list_devices() -> NoReturn:
109109
def default(
110110
ctx: typer.Context,
111111
version: Annotated[
112-
Optional[bool],
112+
bool | None,
113113
typer.Option(
114114
"--version",
115115
callback=version_callback,
@@ -118,7 +118,7 @@ def default(
118118
),
119119
] = None,
120120
device_pattern: Annotated[
121-
Optional[List[str]],
121+
list[str] | None,
122122
typer.Option(
123123
"--device",
124124
help=(
@@ -129,7 +129,7 @@ def default(
129129
),
130130
] = None,
131131
text: Annotated[
132-
Optional[List[str]],
132+
list[str] | None,
133133
typer.Argument(
134134
help="Text, each parameter gives a new line",
135135
rich_help_panel="Elements",
@@ -160,25 +160,25 @@ def default(
160160
),
161161
] = Direction.LEFT,
162162
sample_pattern: Annotated[
163-
Optional[int],
163+
int | None,
164164
typer.Option(help="Prints test pattern of a desired dot height [px]"),
165165
] = None,
166166
min_length: Annotated[
167-
Optional[float],
167+
float | None,
168168
typer.Option(
169169
help="Minimum label length [mm], add whitespace if smaller",
170170
rich_help_panel="Label Dimensions",
171171
),
172172
] = None,
173173
max_length: Annotated[
174-
Optional[float],
174+
float | None,
175175
typer.Option(
176176
help="Maximum label length [mm], error if the label won't fit",
177177
rich_help_panel="Label Dimensions",
178178
),
179179
] = None,
180180
fixed_length: Annotated[
181-
Optional[float],
181+
float | None,
182182
typer.Option(
183183
help="Fixed label length [mm], set both minimum and maximum length",
184184
rich_help_panel="Label Dimensions",
@@ -189,13 +189,13 @@ def default(
189189
typer.Option(help="Destination of the label render"),
190190
] = Output.PRINTER,
191191
font: Annotated[
192-
Optional[str],
192+
str | None,
193193
typer.Option(
194194
help="User font. Overrides --style parameter", rich_help_panel="Design"
195195
),
196196
] = None,
197197
qr_content: Annotated[
198-
Optional[str],
198+
str | None,
199199
typer.Option(
200200
"--qr", callback=qr_callback, help="QR code", rich_help_panel="Elements"
201201
),
@@ -205,7 +205,7 @@ def default(
205205
typer.Option(help="Read batch commands from stdin", rich_help_panel="Elements"),
206206
] = False,
207207
barcode_content: Annotated[
208-
Optional[str],
208+
str | None,
209209
typer.Option("--barcode", help="Barcode", rich_help_panel="Elements"),
210210
] = None,
211211
barcode_type: Annotated[
@@ -216,13 +216,13 @@ def default(
216216
),
217217
] = DEFAULT_BARCODE_TYPE,
218218
barcode_with_text_content: Annotated[
219-
Optional[str],
219+
str | None,
220220
typer.Option(
221221
"--barcode-with-text", help="Barcode with text", rich_help_panel="Elements"
222222
),
223223
] = None,
224224
picture: Annotated[
225-
Optional[Path], typer.Option(help="Picture", rich_help_panel="Elements")
225+
Path | None, typer.Option(help="Picture", rich_help_panel="Elements")
226226
] = None,
227227
margin_px: Annotated[
228228
float,
@@ -235,7 +235,7 @@ def default(
235235
typer.Option(help="Scaling font factor, [0,100] [%]", rich_help_panel="Design"),
236236
] = 90,
237237
tape_size_mm: Annotated[
238-
Optional[int],
238+
int | None,
239239
typer.Option(help="Tape size [mm]", rich_help_panel="Device Configuration"),
240240
] = None,
241241
# Old dymoprint arguments
@@ -281,94 +281,94 @@ def default(
281281
),
282282
] = False,
283283
old_style: Annotated[
284-
Optional[str],
284+
str | None,
285285
typer.Option(
286286
"-s",
287287
help="DEPRECATED",
288288
hidden=True,
289289
),
290290
] = None,
291291
old_align: Annotated[
292-
Optional[str],
292+
str | None,
293293
typer.Option(
294294
"-a",
295295
help="DEPRECATED",
296296
hidden=True,
297297
),
298298
] = None,
299299
old_font: Annotated[
300-
Optional[str],
300+
str | None,
301301
typer.Option(
302302
"-u",
303303
help="DEPRECATED",
304304
hidden=True,
305305
),
306306
] = None,
307307
old_barcode: Annotated[
308-
Optional[str],
308+
str | None,
309309
typer.Option(
310310
"-c",
311311
help="DEPRECATED",
312312
hidden=True,
313313
),
314314
] = None,
315315
barcode_text: Annotated[
316-
Optional[str],
316+
str | None,
317317
typer.Option(
318318
"--barcode-text",
319319
help="DEPRECATED",
320320
hidden=True,
321321
),
322322
] = None,
323323
old_picture: Annotated[
324-
Optional[str],
324+
str | None,
325325
typer.Option(
326326
"-p",
327327
help="DEPRECATED",
328328
hidden=True,
329329
),
330330
] = None,
331331
old_margin: Annotated[
332-
Optional[int],
332+
int | None,
333333
typer.Option(
334334
"-m",
335335
help="DEPRECATED",
336336
hidden=True,
337337
),
338338
] = None,
339339
scale: Annotated[
340-
Optional[float],
340+
float | None,
341341
typer.Option(
342342
help="DEPRECATED",
343343
hidden=True,
344344
),
345345
] = None,
346346
old_tape_size: Annotated[
347-
Optional[int],
347+
int | None,
348348
typer.Option(
349349
"-t",
350350
help="DEPRECATED",
351351
hidden=True,
352352
),
353353
] = None,
354354
old_min_length: Annotated[
355-
Optional[float],
355+
float | None,
356356
typer.Option(
357357
"-l",
358358
help="DEPRECATED",
359359
hidden=True,
360360
),
361361
] = None,
362362
old_justify: Annotated[
363-
Optional[str],
363+
str | None,
364364
typer.Option(
365365
"-j",
366366
help="DEPRECATED",
367367
hidden=True,
368368
),
369369
] = None,
370370
test_pattern: Annotated[
371-
Optional[int],
371+
int | None,
372372
typer.Option(
373373
help="DEPRECATED",
374374
hidden=True,
@@ -504,9 +504,9 @@ def render_text(lines):
504504
render_engines.append(PictureRenderEngine(picture))
505505

506506
if batch:
507-
accumulator: List[str] = []
507+
accumulator: list[str] = []
508508
accumulator_type: str = "empty"
509-
accumulator_options: List[str] = []
509+
accumulator_options: list[str] = []
510510

511511
def flush_all():
512512
nonlocal accumulator

src/labelle/gui/gui.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import logging
22
import sys
3-
from typing import Optional
43

54
from PIL import Image
65
from PyQt6 import QtCore
@@ -26,7 +25,7 @@
2625

2726

2827
class LabelleWindow(QWidget):
29-
_label_bitmap_to_print: Optional[Image.Image]
28+
_label_bitmap_to_print: Image.Image | None
3029
_device_manager: DeviceManager
3130
_dymo_labeler: DymoLabeler
3231
_render_context: RenderContext

src/labelle/gui/q_actions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
from typing import Optional
32

43
from PyQt6 import QtCore
54
from PyQt6.QtCore import QSize, Qt
@@ -12,12 +11,12 @@
1211
class QActions(QWidget):
1312
_error_label: QLabel
1413
_is_enabled: bool
15-
_last_error: Optional[str]
14+
_last_error: str | None
1615
_print_button: QPushButton
1716

1817
print_label_signal = QtCore.pyqtSignal(name="printLabel")
1918

20-
def __init__(self, parent: Optional[QWidget] = None):
19+
def __init__(self, parent: QWidget | None = None):
2120
super().__init__(parent)
2221
self._error_label = QLabel()
2322
self._is_enabled = False

src/labelle/gui/q_labels_list.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
from typing import List, Optional
32

43
from PIL import Image
54
from PyQt6 import QtCore
@@ -74,10 +73,10 @@ class QLabelList(QListWidget):
7473
renderPrintPayloadSignal = QtCore.pyqtSignal(
7574
Image.Image, name="renderPrintPayloadSignal"
7675
)
77-
render_context: Optional[RenderContext]
78-
dymo_labeler: Optional[DymoLabeler]
76+
render_context: RenderContext | None
77+
dymo_labeler: DymoLabeler | None
7978
h_margin_mm: float
80-
min_label_width_mm: Optional[float]
79+
min_label_width_mm: float | None
8180
justify: Direction
8281

8382
def __init__(self, parent=None):
@@ -142,7 +141,7 @@ def update_params(
142141

143142
@property
144143
def _payload_render_engine(self):
145-
render_engines: List[RenderEngine] = []
144+
render_engines: list[RenderEngine] = []
146145
for i in range(self.count()):
147146
item = self.item(i)
148147
item_widget = self.itemWidget(self.item(i))
@@ -206,11 +205,11 @@ def contextMenuEvent(self, event) -> None:
206205
"""
207206
assert self.render_context is not None
208207
contextMenu = QMenu(self)
209-
add_text: Optional[QAction] = contextMenu.addAction("Add Text")
210-
add_qr: Optional[QAction] = contextMenu.addAction("Add QR")
211-
add_barcode: Optional[QAction] = contextMenu.addAction("Add Barcode")
212-
add_img: Optional[QAction] = contextMenu.addAction("Add Image")
213-
delete: Optional[QAction] = contextMenu.addAction("Delete")
208+
add_text: QAction | None = contextMenu.addAction("Add Text")
209+
add_qr: QAction | None = contextMenu.addAction("Add QR")
210+
add_barcode: QAction | None = contextMenu.addAction("Add Barcode")
211+
add_img: QAction | None = contextMenu.addAction("Add Image")
212+
delete: QAction | None = contextMenu.addAction("Delete")
214213
menu_click = contextMenu.exec(event.globalPos())
215214

216215
if menu_click == add_text:

src/labelle/gui/q_render.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
from typing import Optional
32

43
from PIL import Image, ImageQt
54
from PyQt6.QtGui import QPixmap
@@ -9,7 +8,7 @@
98

109

1110
class QRender(QLabel):
12-
def __init__(self, parent: Optional[QWidget] = None) -> None:
11+
def __init__(self, parent: QWidget | None = None) -> None:
1312
super().__init__(parent)
1413
self._init_elements()
1514

src/labelle/lib/barcode_to_image.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# this notice are preserved.
77
# === END LICENSE STATEMENT ===
88

9-
from typing import List, Tuple, Union
109

1110
from PIL import Image, ImageDraw
1211

@@ -17,7 +16,7 @@ def _mm2px(mm: float, dpi: float = 25.4) -> float:
1716
return (mm * dpi) / 25.4
1817

1918

20-
def _list_of_runs(line: BinaryString) -> List[int]:
19+
def _list_of_runs(line: BinaryString) -> list[int]:
2120
# Pack line to list give better gfx result, otherwise in can
2221
# result in aliasing gaps
2322
# '11010111' -> [2, -1, 1, -1, 3]
@@ -43,7 +42,7 @@ def _calculate_size(
4342
module_height: float,
4443
vertical_margin: float,
4544
dpi: float = 25.4,
46-
) -> Tuple[int, int]:
45+
) -> tuple[int, int]:
4746
width = 2 * quiet_zone + modules_per_line * module_width
4847
height = vertical_margin * 2 + module_height
4948
return int(_mm2px(width, dpi)), int(_mm2px(height, dpi))
@@ -99,7 +98,7 @@ def _paint_module(
9998
xpos: float,
10099
ypos: float,
101100
width: float,
102-
color: Union[int, str],
101+
color: int | str,
103102
dpi: float,
104103
module_height: float,
105104
draw: ImageDraw.ImageDraw,

src/labelle/lib/barcode_writer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# this notice are preserved.
77
# === END LICENSE STATEMENT ===
88

9-
from typing import List, NamedTuple, NewType
9+
from typing import NamedTuple, NewType
1010

1111
from barcode.writer import BaseWriter
1212

@@ -39,7 +39,7 @@ def __init__(self) -> None:
3939
finish=_noop,
4040
)
4141

42-
def render(self, code: List[str]) -> BarcodeResult:
42+
def render(self, code: list[str]) -> BarcodeResult:
4343
"""Extract the barcode string from the code and render it into an image."""
4444
if len(code) != 1:
4545
raise ValueError("Barcode expected to have only one line")

0 commit comments

Comments
 (0)