Skip to content

Commit

Permalink
Update code for new versions of linters (#35)
Browse files Browse the repository at this point in the history
* Apply black v2024

* Ignore some bandit warnings
  • Loading branch information
zhiltsov-max authored Mar 13, 2024
1 parent dc66ee5 commit 446bad5
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 22 deletions.
3 changes: 1 addition & 2 deletions datumaro/components/dataset_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ def generate(cls, output_dir, count, shape, **options):
return generator.generate_dataset()

@abstractmethod
def generate_dataset(self):
...
def generate_dataset(self): ...
3 changes: 1 addition & 2 deletions datumaro/components/format_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,7 @@ def __call__(
format_name: str,
reason: RejectionReason,
human_message: str,
) -> Any:
...
) -> Any: ...


def detect_dataset_format(
Expand Down
8 changes: 5 additions & 3 deletions datumaro/plugins/cityscapes_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,11 @@ def apply(self):
compiled_mask = CompiledMask.from_instance_masks(
masks,
instance_ids=[
self._label_id_mapping(m.label)
if m.attributes.get("is_crowd", False)
else self._label_id_mapping(m.label) * 1000 + (m.id or (i + 1))
(
self._label_id_mapping(m.label)
if m.attributes.get("is_crowd", False)
else self._label_id_mapping(m.label) * 1000 + (m.id or (i + 1))
)
for i, m in enumerate(masks)
],
instance_labels=[self._label_id_mapping(m.label) for m in masks],
Expand Down
8 changes: 4 additions & 4 deletions datumaro/plugins/coco_format/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,8 @@ def _split_tasks_string(s):

@classmethod
def build_cmdline_parser(cls, **kwargs):
kwargs[
"description"
] = """
kwargs["description"] = (
"""
Segmentation mask modes ('--segmentation-mode'):|n
- '{sm.guess.name}': guess the mode for each instance,|n
|s|suse 'is_crowd' attribute as hint|n
Expand All @@ -592,7 +591,8 @@ def build_cmdline_parser(cls, **kwargs):
directory, otherwise they are saved in separate directories
by subsets.
""".format(
sm=SegmentationMode
sm=SegmentationMode
)
)
parser = super().build_cmdline_parser(**kwargs)
parser.add_argument(
Expand Down
6 changes: 2 additions & 4 deletions datumaro/plugins/coco_format/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,10 @@ def _get_label_id(self, ann):
return label_id

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

@overload
def _parse_field(self, ann: Dict[str, Any], key: str, cls: Tuple[Type, ...]) -> Any:
...
def _parse_field(self, ann: Dict[str, Any], key: str, cls: Tuple[Type, ...]) -> Any: ...

def _parse_field(
self, ann: Dict[str, Any], key: str, cls: Union[Type[T], Tuple[Type, ...]]
Expand Down
4 changes: 2 additions & 2 deletions datumaro/plugins/sampler/random_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(

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

if self._subset:
n = len(self._extractor.get_subset(self._subset))
Expand Down Expand Up @@ -213,7 +213,7 @@ def _make_bucket():

buckets = defaultdict(_make_bucket) # subset -> subset_buckets

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

for i, item in enumerate(self._extractor):
labels = set(getattr(ann, "label", None) for ann in item.annotations)
Expand Down
9 changes: 6 additions & 3 deletions datumaro/plugins/synthetic_data/image_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ def generate_dataset(self) -> None:

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

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

for i, param, w in zip(indices, params, weights):
image = self._generate_image(
Random(i),
Random(i), # nosec - disable B311
param,
self._iterations,
self._height,
Expand All @@ -119,7 +122,7 @@ def _generate_image_batch(
weight=w,
)
color_image = colorize(image, net)
aug_image = augment(Random(i), color_image, background_colors)
aug_image = augment(Random(i), color_image, background_colors) # nosec - disable B311
save_image(
osp.join(self._output_dir, "{:06d}.png".format(i)), aug_image, create_dir=True
)
Expand Down
4 changes: 2 additions & 2 deletions datumaro/plugins/tf_detection_api_format/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def apply(self):
os.makedirs(self._save_dir, exist_ok=True)

label_categories = self._extractor.categories().get(AnnotationType.label, LabelCategories())
get_label = (
lambda label_id: label_categories.items[label_id].name if label_id is not None else ""
get_label = lambda label_id: (
label_categories.items[label_id].name if label_id is not None else ""
)
label_ids = OrderedDict(
(label.name, 1 + idx) for idx, label in enumerate(label_categories.items)
Expand Down

0 comments on commit 446bad5

Please sign in to comment.