Skip to content

Commit 716659d

Browse files
committed
 Apply some ruff fixes
Signed-off-by: Yuanyuan Chen <cyyever@outlook.com>
1 parent 96d6bf9 commit 716659d

34 files changed

Lines changed: 60 additions & 65 deletions

label_studio/core/bulk_update_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def bulk_update(
166166
cases=(case_template * len(placeholders[field])).format(*placeholders[field]),
167167
type=_get_db_type(field, connection=connection),
168168
)
169-
for field in parameters.keys()
169+
for field in parameters
170170
)
171171

172172
parameters = flatten(parameters.values(), types=list)

label_studio/core/settings/base.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,7 @@
497497
UPLOAD_DIR = 'upload'
498498
AVATAR_PATH = 'avatars'
499499

500-
SUPPORTED_EXTENSIONS = set(
501-
[
500+
SUPPORTED_EXTENSIONS = {
502501
'.bmp',
503502
'.csv',
504503
'.flac',
@@ -521,8 +520,7 @@
521520
'.webm',
522521
'.webp',
523522
'.pdf',
524-
]
525-
)
523+
}
526524

527525
# directory for files created during unit tests
528526
TEST_DATA_ROOT = os.path.join(BASE_DATA_DIR, 'test_data')

label_studio/core/utils/params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def get_env_list_int(key, default=None) -> Sequence[int]:
156156

157157
def get_all_env_with_prefix(prefix=None, is_bool=True, default_value=None):
158158
out = {}
159-
for key in os.environ.keys():
159+
for key in os.environ:
160160
if not key.startswith(prefix):
161161
continue
162162
if is_bool:

label_studio/core/utils/static_serve.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ def serve(request, path, document_root=None, show_indexes=False, manifest_asset_
5454
manifest_asset_prefix = (
5555
f'/{manifest_asset_prefix}' if not manifest_asset_prefix.startswith('/') else manifest_asset_prefix
5656
)
57-
if possible_asset.startswith(manifest_asset_prefix):
58-
possible_asset = possible_asset[len(manifest_asset_prefix) :]
57+
possible_asset = possible_asset.removeprefix(manifest_asset_prefix)
5958
fullpath = Path(safe_join(document_root, possible_asset))
6059
if not fullpath.exists():
6160
raise Http404(_('“%(path)s” does not exist') % {'path': fullpath})

label_studio/data_import/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def read_tasks_list_from_json(self):
158158
if isinstance(tasks, dict):
159159
tasks = [tasks]
160160
tasks_formatted = []
161-
for i, task in enumerate(tasks):
161+
for task in tasks:
162162
if not task.get('data'):
163163
task = {'data': task}
164164
if not isinstance(task['data'], dict):

label_studio/data_import/uploader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def create_file_upload(user, project, file):
7373
instance = FileUpload(user=user, project=project, file=file)
7474
if settings.SVG_SECURITY_CLEANUP:
7575
content_type, encoding = mimetypes.guess_type(str(instance.file.name))
76-
if content_type in ['image/svg+xml']:
76+
if content_type == 'image/svg+xml':
7777
clean_xml = allowlist_svg(instance.file.read().decode())
7878
instance.file.seek(0)
7979
instance.file.write(clean_xml.encode())

label_studio/data_manager/actions/basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def delete_tasks_annotations(project, queryset, **kwargs):
8888
annotations = annotations.filter(completed_by=int(annotator_id))
8989

9090
# take only tasks where annotations are going to be deleted
91-
real_task_ids = set(list(annotations.values_list('task__id', flat=True)))
91+
real_task_ids = set(annotations.values_list('task__id', flat=True))
9292
annotations_ids = list(annotations.values('id'))
9393
# remove deleted annotations from project.summary
9494
project.summary.remove_created_annotations_and_labels(annotations)
@@ -155,7 +155,7 @@ def delete_tasks_predictions(project, queryset, **kwargs):
155155
if flag_set('fflag_root_223_optimize_delete_predictions', organization=project.organization):
156156
real_task_ids = predictions.order_by().values_list('task_id', flat=True).distinct()
157157
else:
158-
real_task_ids = set(list(predictions.values_list('task_id', flat=True)))
158+
real_task_ids = set(predictions.values_list('task_id', flat=True))
159159

160160
count = predictions.count()
161161
predictions.delete()

label_studio/data_manager/actions/cache_labels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def cache_labels_job(project, queryset, **kwargs):
5353
)
5454
# no counters
5555
else:
56-
task.data[column_name] = ', '.join(sorted(list(set(task_labels))))
56+
task.data[column_name] = ', '.join(sorted(set(task_labels)))
5757

5858
Task.objects.bulk_update(tasks, fields=['data'], batch_size=1000)
5959
first_task = Task.objects.get(id=queryset.first().id)

label_studio/data_manager/actions/experimental.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def add_data_field(project, queryset, **kwargs):
166166
size = queryset.count()
167167

168168
cast = {'String': str, 'Number': float, 'Expression': str}
169-
assert value_type in cast.keys()
169+
assert value_type in cast
170170
value = cast[value_type](value)
171171

172172
if value_type == 'Expression':

label_studio/data_manager/functions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,7 @@ def preprocess_field_name(raw_field_name, project) -> Tuple[str, bool]:
384384
# For security reasons, these must only be removed when they fall at the beginning of the string (or after `-`).
385385
optional_prefixes = ['filter:', 'tasks:']
386386
for prefix in optional_prefixes:
387-
if field_name.startswith(prefix):
388-
field_name = field_name[len(prefix) :]
387+
field_name = field_name.removeprefix(prefix)
389388

390389
# Descending marker may also come after other prefixes. Double negative is not allowed.
391390
if ascending and field_name.startswith('-'):
@@ -400,7 +399,7 @@ def preprocess_field_name(raw_field_name, project) -> Tuple[str, bool]:
400399
# there is only one object tag in labeling config
401400
# and requested filter name == value from object tag
402401
len(project.data_types.keys()) == 1
403-
and real_name in project.data_types.keys()
402+
and real_name in project.data_types
404403
# file was uploaded before labeling config is set, `data.data` is system predefined name
405404
or len(project.data_types.keys()) == 0
406405
and real_name == 'data'

0 commit comments

Comments
 (0)