Skip to content

Commit 0012445

Browse files
committed
 Apply some ruff fixes
Signed-off-by: Yuanyuan Chen <cyyever@outlook.com>
1 parent 8882a61 commit 0012445

37 files changed

Lines changed: 65 additions & 70 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/label_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ def get_task_from_labeling_config(config):
227227
logger.debug(json.dumps(body, indent=2))
228228
dont_use_root = 'predictions' in body or 'annotations' in body
229229
task_data = body['data'] if 'data' in body else (None if dont_use_root else body)
230-
predictions = body['predictions'] if 'predictions' in body else None
231-
annotations = body['annotations'] if 'annotations' in body else None
230+
predictions = body.get('predictions', None)
231+
annotations = body.get('annotations', None)
232232
return task_data, annotations, predictions
233233

234234

label_studio/core/middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def process_request(self, request) -> None:
211211
return
212212

213213
current_time = time.time()
214-
last_login = request.session['last_login'] if 'last_login' in request.session else 0
214+
last_login = request.session.get('last_login', 0)
215215

216216
active_org = request.user.active_organization
217217
if active_org:

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def float_from_request(params, key, default):
7878
except ValueError:
7979
raise ValidationError({key: f'Incorrect value in key "{key}" = "{value}". It should be digit string.'})
8080
# float
81-
elif isinstance(value, float) or isinstance(value, int):
81+
elif isinstance(value, (float, int)):
8282
return float(value)
8383
# other
8484
else:
@@ -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)

0 commit comments

Comments
 (0)