Skip to content

Commit 215c615

Browse files
authored
Merge pull request #1635 from wkentaro/ruff_pyupgrade
Enable pyupgrade check in ruff
2 parents 95e1e2a + 9f67d10 commit 215c615

22 files changed

+37
-58
lines changed

Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ setup: # Setup the development environment
2828
$(call exec,uv sync --dev)
2929

3030
format: # Format code
31-
$(call exec,uv run flynt .)
3231
$(call exec,uv run ruff format)
3332
$(call exec,uv run ruff check --fix)
3433

3534
lint:
36-
$(call exec,uv run flynt . --fail-on-change)
3735
$(call exec,uv run ruff format --check)
3836
$(call exec,uv run ruff check)
3937

examples/bbox_detection/labelme2voc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python
22

3-
from __future__ import print_function
43

54
import argparse
65
import glob

examples/instance_segmentation/labelme2voc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python
22

3-
from __future__ import print_function
43

54
import argparse
65
import glob

examples/tutorial/load_label_png.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python
22

3-
from __future__ import print_function
43

54
import os.path as osp
65

@@ -29,7 +28,7 @@ def main():
2928

3029
print("label: label_name")
3130
for label, label_name in zip(labels, label_names):
32-
print("%d: %s" % (label, label_name))
31+
print(f"{label}: {label_name}")
3332

3433

3534
if __name__ == "__main__":

labelme/_label_file.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import base64
2+
import builtins
23
import contextlib
34
import io
45
import json
@@ -21,7 +22,7 @@
2122
def open(name, mode):
2223
assert mode in ["r", "w"]
2324
encoding = "utf-8"
24-
yield io.open(name, mode, encoding=encoding)
25+
yield builtins.open(name, mode, encoding=encoding)
2526
return
2627

2728

@@ -124,7 +125,7 @@ class LabelFileError(Exception):
124125
pass
125126

126127

127-
class LabelFile(object):
128+
class LabelFile:
128129
shapes: list[ShapeDict]
129130
suffix = ".json"
130131

@@ -140,7 +141,7 @@ def __init__(self, filename=None):
140141
def load_image_file(filename):
141142
try:
142143
image_pil = PIL.Image.open(filename)
143-
except IOError:
144+
except OSError:
144145
logger.error(f"Failed opening image file: {filename}")
145146
return
146147

labelme/app.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
import functools
42
import html
53
import math
@@ -93,7 +91,7 @@ def __init__(
9391
# Set point size from config file
9492
Shape.point_size = self._config["shape"]["point_size"]
9593

96-
super(MainWindow, self).__init__()
94+
super().__init__()
9795
self.setWindowTitle(__appname__)
9896

9997
# Whether we need to save or not.
@@ -1136,7 +1134,7 @@ def exists(filename):
11361134
for i, f in enumerate(files):
11371135
icon = utils.newIcon("labels")
11381136
action = QtWidgets.QAction(
1139-
icon, "&%d %s" % (i + 1, QtCore.QFileInfo(f).fileName()), self
1137+
icon, f"&{i + 1} {QtCore.QFileInfo(f).fileName()}", self
11401138
)
11411139
action.triggered.connect(functools.partial(self.loadRecent, f))
11421140
menu.addAction(action)
@@ -1752,7 +1750,7 @@ def resizeEvent(self, event):
17521750
and self.zoomMode != self.MANUAL_ZOOM
17531751
):
17541752
self.adjustScale()
1755-
super(MainWindow, self).resizeEvent(event)
1753+
super().resizeEvent(event)
17561754

17571755
def paintCanvas(self):
17581756
assert not self.image.isNull(), "cannot paint null image"

labelme/cli/draw_label_png.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def main():
4646
logger.info(
4747
"Label names: {}".format(
4848
[
49-
"{}:{}".format(label_value, label_names[label_value])
49+
f"{label_value}:{label_names[label_value]}"
5050
for label_value in unique_label_values
5151
]
5252
)

labelme/cli/on_docker.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python
22

3-
from __future__ import print_function
43

54
import argparse
65
import json

labelme/shape.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# - [opt] Store paths instead of creating new ones at each paint.
1313

1414

15-
class Shape(object):
15+
class Shape:
1616
# Render handles as squares
1717
P_SQUARE = 0
1818

labelme/utils/_io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ def lblsave(filename, lbl):
2121
lbl_pil.save(filename)
2222
else:
2323
raise ValueError(
24-
"[%s] Cannot save the pixel-wise class label as PNG. "
25-
"Please consider using the .npy format." % filename
24+
f"[{filename}] Cannot save the pixel-wise class label as PNG. "
25+
"Please consider using the .npy format."
2626
)

0 commit comments

Comments
 (0)