Skip to content

Commit 446bad5

Browse files
authored
Update code for new versions of linters (#35)
* Apply black v2024 * Ignore some bandit warnings
1 parent dc66ee5 commit 446bad5

File tree

8 files changed

+23
-22
lines changed

8 files changed

+23
-22
lines changed

datumaro/components/dataset_generator.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ def generate(cls, output_dir, count, shape, **options):
1818
return generator.generate_dataset()
1919

2020
@abstractmethod
21-
def generate_dataset(self):
22-
...
21+
def generate_dataset(self): ...

datumaro/components/format_detection.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,7 @@ def __call__(
445445
format_name: str,
446446
reason: RejectionReason,
447447
human_message: str,
448-
) -> Any:
449-
...
448+
) -> Any: ...
450449

451450

452451
def detect_dataset_format(

datumaro/plugins/cityscapes_format.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,11 @@ def apply(self):
442442
compiled_mask = CompiledMask.from_instance_masks(
443443
masks,
444444
instance_ids=[
445-
self._label_id_mapping(m.label)
446-
if m.attributes.get("is_crowd", False)
447-
else self._label_id_mapping(m.label) * 1000 + (m.id or (i + 1))
445+
(
446+
self._label_id_mapping(m.label)
447+
if m.attributes.get("is_crowd", False)
448+
else self._label_id_mapping(m.label) * 1000 + (m.id or (i + 1))
449+
)
448450
for i, m in enumerate(masks)
449451
],
450452
instance_labels=[self._label_id_mapping(m.label) for m in masks],

datumaro/plugins/coco_format/converter.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,8 @@ def _split_tasks_string(s):
566566

567567
@classmethod
568568
def build_cmdline_parser(cls, **kwargs):
569-
kwargs[
570-
"description"
571-
] = """
569+
kwargs["description"] = (
570+
"""
572571
Segmentation mask modes ('--segmentation-mode'):|n
573572
- '{sm.guess.name}': guess the mode for each instance,|n
574573
|s|suse 'is_crowd' attribute as hint|n
@@ -592,7 +591,8 @@ def build_cmdline_parser(cls, **kwargs):
592591
directory, otherwise they are saved in separate directories
593592
by subsets.
594593
""".format(
595-
sm=SegmentationMode
594+
sm=SegmentationMode
595+
)
596596
)
597597
parser = super().build_cmdline_parser(**kwargs)
598598
parser.add_argument(

datumaro/plugins/coco_format/extractor.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,10 @@ def _get_label_id(self, ann):
292292
return label_id
293293

294294
@overload
295-
def _parse_field(self, ann: Dict[str, Any], key: str, cls: Type[T]) -> T:
296-
...
295+
def _parse_field(self, ann: Dict[str, Any], key: str, cls: Type[T]) -> T: ...
297296

298297
@overload
299-
def _parse_field(self, ann: Dict[str, Any], key: str, cls: Tuple[Type, ...]) -> Any:
300-
...
298+
def _parse_field(self, ann: Dict[str, Any], key: str, cls: Tuple[Type, ...]) -> Any: ...
301299

302300
def _parse_field(
303301
self, ann: Dict[str, Any], key: str, cls: Union[Type[T], Tuple[Type, ...]]

datumaro/plugins/sampler/random_sampler.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(
6767

6868
def __iter__(self):
6969
if self._indices is None:
70-
rng = Random(self._seed)
70+
rng = Random(self._seed) # nosec - disable B311
7171

7272
if self._subset:
7373
n = len(self._extractor.get_subset(self._subset))
@@ -213,7 +213,7 @@ def _make_bucket():
213213

214214
buckets = defaultdict(_make_bucket) # subset -> subset_buckets
215215

216-
rng = Random(self._seed)
216+
rng = Random(self._seed) # nosec - disable B311
217217

218218
for i, item in enumerate(self._extractor):
219219
labels = set(getattr(ann, "label", None) for ann in item.annotations)

datumaro/plugins/synthetic_data/image_generator.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ def generate_dataset(self) -> None:
6666

6767
mp_ctx = get_context("spawn") # On Mac 10.15 and Python 3.7 fork leads to hangs
6868
with mp_ctx.Pool(processes=self._cpu_count) as pool:
69-
params = pool.map(self._generate_category, [Random(i) for i in range(self._categories)])
69+
params = pool.map(
70+
self._generate_category,
71+
[Random(i) for i in range(self._categories)], # nosec - disable B311
72+
)
7073

7174
instances_weights = np.repeat(self._weights, self._instances, axis=0)
7275
weight_per_img = np.tile(instances_weights, (self._categories, 1))
@@ -110,7 +113,7 @@ def _generate_image_batch(
110113

111114
for i, param, w in zip(indices, params, weights):
112115
image = self._generate_image(
113-
Random(i),
116+
Random(i), # nosec - disable B311
114117
param,
115118
self._iterations,
116119
self._height,
@@ -119,7 +122,7 @@ def _generate_image_batch(
119122
weight=w,
120123
)
121124
color_image = colorize(image, net)
122-
aug_image = augment(Random(i), color_image, background_colors)
125+
aug_image = augment(Random(i), color_image, background_colors) # nosec - disable B311
123126
save_image(
124127
osp.join(self._output_dir, "{:06d}.png".format(i)), aug_image, create_dir=True
125128
)

datumaro/plugins/tf_detection_api_format/converter.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def apply(self):
7373
os.makedirs(self._save_dir, exist_ok=True)
7474

7575
label_categories = self._extractor.categories().get(AnnotationType.label, LabelCategories())
76-
get_label = (
77-
lambda label_id: label_categories.items[label_id].name if label_id is not None else ""
76+
get_label = lambda label_id: (
77+
label_categories.items[label_id].name if label_id is not None else ""
7878
)
7979
label_ids = OrderedDict(
8080
(label.name, 1 + idx) for idx, label in enumerate(label_categories.items)

0 commit comments

Comments
 (0)