From 7dcdca3bf4c98b2542966ae5d7d2723ebb73e8dd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 8 Aug 2023 01:53:47 +0200 Subject: [PATCH] Replace `type(1) == int` with `isinstance(1, int)` (#4217) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Glenn Jocher --- .pre-commit-config.yaml | 4 ++-- ultralytics/engine/results.py | 4 ++-- ultralytics/models/fastsam/prompt.py | 4 ++-- ultralytics/utils/__init__.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 53f782f..efbdd7c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,7 +22,7 @@ repos: - id: detect-private-key - repo: https://github.com/asottile/pyupgrade - rev: v3.8.0 + rev: v3.10.1 hooks: - id: pyupgrade name: Upgrade code @@ -50,7 +50,7 @@ repos: # exclude: "README.md|README.zh-CN.md|CONTRIBUTING.md" - repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 + rev: 6.1.0 hooks: - id: flake8 name: PEP8 diff --git a/ultralytics/engine/results.py b/ultralytics/engine/results.py index c387dc5..60b57bf 100644 --- a/ultralytics/engine/results.py +++ b/ultralytics/engine/results.py @@ -221,12 +221,12 @@ class Results(SimpleClass): if 'show_conf' in kwargs: deprecation_warn('show_conf', 'conf') conf = kwargs['show_conf'] - assert type(conf) == bool, '`show_conf` should be of boolean type, i.e, show_conf=True/False' + assert isinstance(conf, bool), '`show_conf` should be of boolean type, i.e, show_conf=True/False' if 'line_thickness' in kwargs: deprecation_warn('line_thickness', 'line_width') line_width = kwargs['line_thickness'] - assert type(line_width) == int, '`line_width` should be of int type, i.e, line_width=3' + assert isinstance(line_width, int), '`line_width` should be of int type, i.e, line_width=3' names = self.names pred_boxes, show_boxes = self.boxes, boxes diff --git a/ultralytics/models/fastsam/prompt.py b/ultralytics/models/fastsam/prompt.py index 6cee91d..ead6319 100644 --- a/ultralytics/models/fastsam/prompt.py +++ b/ultralytics/models/fastsam/prompt.py @@ -158,7 +158,7 @@ class FastSAMPrompt: contour_all = [] temp = np.zeros((original_h, original_w, 1)) for i, mask in enumerate(annotations): - if type(mask) == dict: + if isinstance(mask, dict): mask = mask['segmentation'] annotation = mask.astype(np.uint8) if not retina: @@ -383,7 +383,7 @@ class FastSAMPrompt: points = [[int(point[0] * w / target_width), int(point[1] * h / target_height)] for point in points] onemask = np.zeros((h, w)) for i, annotation in enumerate(masks): - mask = annotation['segmentation'] if type(annotation) == dict else annotation + mask = annotation['segmentation'] if isinstance(annotation, dict) else annotation for i, point in enumerate(points): if mask[point[1], point[0]] == 1 and pointlabel[i] == 1: onemask += mask diff --git a/ultralytics/utils/__init__.py b/ultralytics/utils/__init__.py index 58162aa..0d213f3 100644 --- a/ultralytics/utils/__init__.py +++ b/ultralytics/utils/__init__.py @@ -791,7 +791,7 @@ class SettingsManager(dict): self.load() correct_keys = self.keys() == self.defaults.keys() - correct_types = all(type(a) == type(b) for a, b in zip(self.values(), self.defaults.values())) + correct_types = all(type(a) is type(b) for a, b in zip(self.values(), self.defaults.values())) correct_version = check_version(self['settings_version'], self.version) if not (correct_keys and correct_types and correct_version): LOGGER.warning(