Skip to content

Commit

Permalink
Address syntax warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
d-mo committed Nov 25, 2022
1 parent ed6367a commit 45f3499
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/mist/api/machines/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def create_machine(request):
if not isinstance(mtags, dict):
if not isinstance(mtags, list):
raise ValueError()
if not all((isinstance(t, dict) and len(t) is 1 for t in mtags)):
if not all((isinstance(t, dict) and len(t) == 1 for t in mtags)):
raise ValueError()
mtags = {key: val for item in mtags for key,
val in list(item.items())}
Expand Down
2 changes: 1 addition & 1 deletion src/mist/api/metering/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _parse_checks_or_datapoints_series(results, field, owner_id=''):
for start_iso, result in results:
for series in result:
values = series.get('values', [])
assert len(values) is 1, 'Expected a single value. Got %s' % values
assert len(values) == 1, 'Expected a single value. Got %s' % values
value = values[0][-1]
value = int(round(value)) if value else None
owner = series.get('tags', {}).get('owner', owner_id)
Expand Down
2 changes: 1 addition & 1 deletion src/mist/api/monitoring/influxdb/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def parse_path(self, metric):
if len(fields) > 1:
for tag in fields[:-1]:
tag = tag.split('=')
if len(tag) is not 2:
if len(tag) != 2:
log.error('%s got unexpected tag: %s',
self.__class__.__name__, tag)
continue
Expand Down
4 changes: 2 additions & 2 deletions src/mist/api/rules/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,15 @@ def includes_only(self, resource):
return False

# The rule contains multiple selectors.
if len(self.rule.selectors) is not 1:
if len(self.rule.selectors) != 1:
return False

# The rule does not refer to resources by their UUID.
if not isinstance(self.rule.selectors[0], ResourceSelector):
return False

# The rule refers to multiple resources.
if len(self.rule.selectors[0].ids) is not 1:
if len(self.rule.selectors[0].ids) != 1:
return False

# The rule's single resource does not match `resource`.
Expand Down
4 changes: 2 additions & 2 deletions src/mist/api/rules/models/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ def as_dict(self):
return {'offset': self.offset, 'period': self.period}

def __str__(self):
if self.offset is 0:
if self.offset == 0:
return 'Trigger offset is 0'
if self.offset is 1:
if self.offset == 1:
return 'Trigger offset of 1 %s' % self.period_singular
return 'Trigger offset %s %s' % (self.offset, self.period)
8 changes: 4 additions & 4 deletions src/mist/api/rules/models/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,22 +351,22 @@ def as_dict(self):

@property
def metric(self):
assert len(self.queries) is 1
assert len(self.queries) == 1
return self.queries[0].target

@property
def operator(self):
assert len(self.queries) is 1
assert len(self.queries) == 1
return self.queries[0].operator

@property
def value(self):
assert len(self.queries) is 1
assert len(self.queries) == 1
return self.queries[0].threshold

@property
def aggregate(self):
assert len(self.queries) is 1
assert len(self.queries) == 1
return self.queries[0].aggregation

@property
Expand Down
6 changes: 3 additions & 3 deletions src/mist/api/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def disconnect(self, **kwargs):
pass

def _wrap_command(self, cmd):
if cmd[-1] is not "\n":
if cmd[-1] != "\n":
cmd = cmd + "\n"
return cmd

Expand Down Expand Up @@ -611,7 +611,7 @@ def set_ws_data(self, uuid, secret, control):
self._control = control

def _wrap_command(self, cmd):
if cmd[-1] is not "\r":
if cmd[-1] != "\r":
cmd = cmd + "\r"
return cmd

Expand Down Expand Up @@ -741,7 +741,7 @@ def disconnect(self, **kwargs):
pass

def _wrap_command(self, cmd):
if cmd[-1] is not "\n":
if cmd[-1] != "\n":
cmd = cmd + "\n"
return cmd

Expand Down
2 changes: 1 addition & 1 deletion src/mist/api/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ def clean(self):
elif team.name == 'Owners':
raise me.ValidationError(
'RBAC Mappings are not intended for Team Owners')
elif len(mappings) is not 2:
elif len(mappings) != 2:
raise me.ValidationError(
'RBAC Mappings have not been properly initialized for '
'Team %s' % team)
Expand Down
4 changes: 2 additions & 2 deletions src/mist/api/when/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ def as_dict(self):
return {'offset': self.offset, 'period': self.period}

def __str__(self):
if self.offset is 0:
if self.offset == 0:
return 'Trigger offset is 0'
if self.offset is 1:
if self.offset == 1:
return 'Trigger offset of 1 %s' % self.period_singular
return 'Trigger offset %s %s' % (self.offset, self.period)

0 comments on commit 45f3499

Please sign in to comment.