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 <glenn.jocher@ultralytics.com>
pull/4230/head
pre-commit-ci[bot] 1 year ago committed by GitHub
parent ff5fa57415
commit 7dcdca3bf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      .pre-commit-config.yaml
  2. 4
      ultralytics/engine/results.py
  3. 4
      ultralytics/models/fastsam/prompt.py
  4. 2
      ultralytics/utils/__init__.py

@ -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

@ -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

@ -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

@ -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(

Loading…
Cancel
Save