Skip to content

Commit

Permalink
Fix some warnings from new Pylint
Browse files Browse the repository at this point in the history
I tried to update Pylint to the most recent version (3.2.2), which produced
a bunch of new warnings. I couldn't fix all of them in one sitting, but I
fixed some.
  • Loading branch information
SpecLad committed May 28, 2024
1 parent 49b10ba commit 39e180b
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 32 deletions.
2 changes: 1 addition & 1 deletion cvat-sdk/cvat_sdk/auto_annotation/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def label_spec(name: str, id: int, **kwargs) -> models.PatchedLabelRequest:
return models.PatchedLabelRequest(name=name, id=id, **kwargs)


# pylint: disable-next=redefined-builtin
def skeleton_label_spec(
# pylint: disable-next=redefined-builtin
name: str, id: int, sublabels: Sequence[models.SublabelRequest], **kwargs
) -> models.PatchedLabelRequest:
"""Helper factory function for PatchedLabelRequest with type="skeleton"."""
Expand Down
2 changes: 1 addition & 1 deletion cvat/apps/dataset_manager/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ def simple_interpolation(shape0, shape1):

def simple_3d_interpolation(shape0, shape1):
result = simple_interpolation(shape0, shape1)
angles = (shape0["points"][3:6] + shape1["points"][3:6])
angles = shape0["points"][3:6] + shape1["points"][3:6]
distance = shape1["frame"] - shape0["frame"]

for shape in result:
Expand Down
4 changes: 3 additions & 1 deletion cvat/apps/dataset_manager/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,8 @@ def __init__(
annotations=dm_anno, media=PointCloud(dm_image[0]), related_images=dm_image[1],
attributes=attributes
)
else:
assert False, f"Unexpected value for dimension: {dimension!r}"

dm_items.append(dm_item)

Expand Down Expand Up @@ -1728,7 +1730,7 @@ def _convert_attrs(self, label: CommonData.Label, cvat_attrs: CommonData.Attribu
if a_desc['input_type'] == AttributeType.NUMBER:
a_value = float(a_value)
elif a_desc['input_type'] == AttributeType.CHECKBOX:
a_value = (a_value.lower() == 'true')
a_value = a_value.lower() == 'true'
dm_attr[a_name] = a_value
except Exception as e:
raise Exception(
Expand Down
12 changes: 6 additions & 6 deletions cvat/apps/dataset_manager/formats/cvat.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,15 @@ def _parse(cls, path):
if el.tag == 'points' and el.attrib.get('occluded') == '1':
shape_element['visibility'] = [Points.Visibility.hidden] * (len(shape_element['points']) // 2)
else:
shape_element['occluded'] = (el.attrib.get('occluded') == '1')
shape_element['occluded'] = el.attrib.get('occluded') == '1'

if el.tag == 'points' and el.attrib.get('outside') == '1':
shape_element['visibility'] = [Points.Visibility.absent] * (len(shape_element['points']) // 2)
else:
shape_element['outside'] = (el.attrib.get('outside') == '1')
shape_element['outside'] = el.attrib.get('outside') == '1'

if track:
shape_element['keyframe'] = (el.attrib.get('keyframe') == '1')
shape_element['keyframe'] = el.attrib.get('keyframe') == '1'
if shape_element['keyframe']:
track_elements.append(shape_element)
else:
Expand All @@ -246,14 +246,14 @@ def _parse(cls, path):
elif el.tag in cls._SUPPORTED_SHAPES:
if track is not None:
shape['frame'] = el.attrib['frame']
shape['outside'] = (el.attrib.get('outside') == '1')
shape['keyframe'] = (el.attrib.get('keyframe') == '1')
shape['outside'] = el.attrib.get('outside') == '1'
shape['keyframe'] = el.attrib.get('keyframe') == '1'
if image is not None:
shape['label'] = el.attrib.get('label')
shape['group'] = int(el.attrib.get('group_id', 0))

shape['type'] = el.tag
shape['occluded'] = (el.attrib.get('occluded') == '1')
shape['occluded'] = el.attrib.get('occluded') == '1'
shape['z_order'] = int(el.attrib.get('z_order', 0))
shape['rotation'] = float(el.attrib.get('rotation', 0))

Expand Down
2 changes: 2 additions & 0 deletions cvat/apps/dataset_manager/formats/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def __call__(self, *args, **kwargs):
wrapper.__name__ = f_or_cls.__name__
wrapper.__module__ = f_or_cls.__module__
target = wrapper
else:
assert False, "f_or_cls must be a class or a function"

target.NAME = name or klass.NAME or f_or_cls.__name__
target.VERSION = version or klass.VERSION
Expand Down
4 changes: 4 additions & 0 deletions cvat/apps/dataset_manager/tests/test_rest_api_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ def _create_annotations(self, task, name_ann, key_get_values):
value = random.choice(task["labels"][0]["attributes"][index_attribute]["values"])
elif key_get_values == "default":
value = attribute["default_value"]
else:
assert False, f"Unexpected key_get_values value: {key_get_values!r}"

if item == "tracks" and attribute["mutable"]:
for index_shape, _ in enumerate(tmp_annotations[item][index_elem]["shapes"]):
Expand Down Expand Up @@ -308,6 +310,8 @@ def _create_annotations_in_job(self, task, job_id, name_ann, key_get_values):
value = random.choice(task["labels"][0]["attributes"][index_attribute]["values"])
elif key_get_values == "default":
value = attribute["default_value"]
else:
assert False, f"Unexpected key_get_values value: {key_get_values!r}"

if item == "tracks" and attribute["mutable"]:
for index_shape, _ in enumerate(tmp_annotations[item][index_elem]["shapes"]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def split_text_attribute(apps, schema_editor):
for attribute in AttributeSpec.objects.all():
spec = parse_attribute(attribute.text)
if spec:
attribute.mutable = (spec['prefix'] == '~')
attribute.mutable = spec['prefix'] == '~'
attribute.input_type = spec['type']
attribute.name = spec['name']
attribute.default_value = spec['values'][0] if spec['values'] else ''
Expand Down
6 changes: 3 additions & 3 deletions cvat/apps/engine/migrations/0024_auto_20191023_1025.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def migrate_task_data(db_task_id, db_data_id, original_video, original_images, s
compressed_chunk_path = os.path.join(compressed_cache_dir, '{}.zip'.format(chunk_idx))
compressed_chunk_writer.save_as_chunk(chunk_images, compressed_chunk_path)

preview = reader.get_preview()
preview = reader.get_preview(0)
preview.save(os.path.join(db_data_dir, 'preview.jpeg'))
else:
original_chunk_writer = ZipChunkWriter(100)
Expand Down Expand Up @@ -146,7 +146,7 @@ def migrate_task_data(db_task_id, db_data_id, original_video, original_images, s
original_chunk_path = os.path.join(original_cache_dir, '{}.zip'.format(chunk_idx))
original_chunk_writer.save_as_chunk(chunk_images, original_chunk_path)

preview = reader.get_preview()
preview = reader.get_preview(0)
preview.save(os.path.join(db_data_dir, 'preview.jpeg'))
shutil.rmtree(old_db_task_dir)
return_dict[db_task_id] = (True, '')
Expand Down Expand Up @@ -284,7 +284,7 @@ def create_process(db_task_id, db_data_id):
if res.exitcode == 0:
ret_code, message = return_dict[res_idx]
if ret_code:
counter = (task_idx - len(results))
counter = task_idx - len(results)
progress = (100 * counter) / task_count
log.info('Data migration for the task {} completed. Progress: {:.02f}% | {}/{}.'.format(res_idx, progress, counter, task_count))
else:
Expand Down
12 changes: 6 additions & 6 deletions cvat/apps/engine/migrations/0034_auto_20201125_1426.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import django.db.models.deletion

def create_profile(apps, schema_editor):
User = apps.get_model('auth', 'User')
Profile = apps.get_model('engine', 'Profile')
for user in User.objects.all():
profile = Profile()
profile.user = user
profile.save()
User = apps.get_model('auth', 'User')
Profile = apps.get_model('engine', 'Profile')
for user in User.objects.all():
profile = Profile()
profile.user = user
profile.save()

class Migration(migrations.Migration):

Expand Down
2 changes: 1 addition & 1 deletion cvat/apps/engine/migrations/0038_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def migrate2manifest(apps, shema_editor):

if db_data.storage == StorageChoice.SHARE:
def _get_frame_step(str_):
match = search("step\s*=\s*([1-9]\d*)", str_)
match = search(r"step\s*=\s*([1-9]\d*)", str_)
return int(match.group(1)) if match else 1
logger.info('Data is located on the share, metadata update has been started')
manifest.step = _get_frame_step(db_data.frame_filter)
Expand Down
2 changes: 2 additions & 0 deletions cvat/apps/engine/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ def update(self, instance, validated_data):
parent_serializer = TaskWriteSerializer(
instance=instance.task, data=parent_query, partial=True,
)
else:
assert False, f"Label {instance.id} is not attached to either a project or a task"

parent_serializer.is_valid(raise_exception=True)
parent_serializer.save()
Expand Down
13 changes: 6 additions & 7 deletions cvat/apps/webhooks/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,29 +139,28 @@ def pre_save_resource_event(sender, instance, **kwargs):
instance._webhooks_selected_webhooks = []

if instance.pk is None:
created = True
old_instance = None
else:
try:
old_instance = sender.objects.get(pk=instance.pk)
created = False
except ObjectDoesNotExist:
created = True
old_instance = None

resource_name = instance.__class__.__name__.lower()

event_type = event_name("create" if created else "update", resource_name)
event_type = event_name("update" if old_instance else "create", resource_name)
if event_type not in map(lambda a: a[0], EventTypeChoice.choices()):
return

instance._webhooks_selected_webhooks = select_webhooks(instance, event_type)
if not instance._webhooks_selected_webhooks:
return

if created:
instance._webhooks_old_data = None
else:
if old_instance:
old_serializer = get_serializer(instance=old_instance)
instance._webhooks_old_data = old_serializer.data
else:
instance._webhooks_old_data = None

@receiver(post_save, sender=Project, dispatch_uid=__name__ + ":project:post_save")
@receiver(post_save, sender=Task, dispatch_uid=__name__ + ":task:post_save")
Expand Down
5 changes: 4 additions & 1 deletion serverless/pytorch/foolwood/siammask/nuclio/model_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
#
# SPDX-License-Identifier: MIT

from tools.test import *
import os
from copy import copy

import jsonpickle
import numpy as np
import torch

from tools.test import load_config, load_pretrain, siamese_init, siamese_track

class ModelHandler:
def __init__(self):
Expand Down
6 changes: 6 additions & 0 deletions tests/python/rest_api/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def test_project_admin_accessibility(self, projects, find_users, is_project_staf

# Project owner or project assignee can see project.
def test_project_owner_accessibility(self, projects):
project_with_owner = project_with_assignee = None

for p in projects:
if p["owner"] is not None:
project_with_owner = p
Expand Down Expand Up @@ -1038,6 +1040,8 @@ def test_project_preview_admin_accessibility(

# Project owner or project assignee can see project preview.
def test_project_preview_owner_accessibility(self, projects):
project_with_owner = project_with_assignee = None

for p in projects:
if not p["tasks"]:
continue
Expand All @@ -1055,6 +1059,8 @@ def test_project_preview_owner_accessibility(self, projects):
)

def test_project_preview_not_found(self, projects, tasks):
project_with_owner = project_with_assignee = None

for p in projects:
if any(t["project_id"] == p["id"] for t in tasks):
continue
Expand Down
6 changes: 3 additions & 3 deletions utils/dataset_manifest/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

from utils import detect_related_images, is_image, is_video, SortingMethod

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from dataset_manifest.core import VideoManifestManager, ImageManifestManager

def get_args():
parser = argparse.ArgumentParser()
parser.add_argument('--force', action='store_true',
Expand Down Expand Up @@ -96,7 +99,4 @@ def main():
print('The manifest file has been prepared')

if __name__ == "__main__":
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(base_dir)
from dataset_manifest.core import VideoManifestManager, ImageManifestManager
main()
2 changes: 1 addition & 1 deletion utils/dicom_converter/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __iter__(self):

# In some cases we need to convert colors additionally
if 'YBR' in self._photometric_interpretation:
pixel_array = convert_color_space(pixel_array, self._photometric_interpretation, 'RGB')
pixel_array = convert_color_space(pixel_array, self._photometric_interpretation, 'RGB')

if self._depth == 8:
image = Image.fromarray(pixel_array.astype(np.uint8))
Expand Down

0 comments on commit 39e180b

Please sign in to comment.