From afc688fedad5303a2690ccb074ce0d9fc221fb80 Mon Sep 17 00:00:00 2001 From: Joey Orlando Date: Tue, 2 Apr 2024 10:26:19 -0400 Subject: [PATCH] upgrade flake8 to v7 (#4141) # Which issue(s) this PR closes Fixes [this issue](https://github.com/grafana/oncall-private/pull/2620/files#diff-0144920543fd191db13f76c9fb797116e26eda2bdd2b79332b61bfbf5846208eR193-R197) (https://github.com/PyCQA/pycodestyle/issues/334#issuecomment-2027394413) in `grafana/oncall-private` ## Checklist - [ ] Unit, integration, and e2e (if applicable) tests updated (N/A) - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] Added the relevant release notes label (see labels prefixed w/ `release:`). These labels dictate how your PR will show up in the autogenerated release notes. --- .pre-commit-config.yaml | 2 +- engine/apps/alerts/models/alert_group.py | 6 +++--- engine/apps/api/tests/test_alert_receive_channel.py | 4 ++-- engine/apps/api/views/alert_receive_channel.py | 4 ++-- engine/apps/base/tests/test_live_settings.py | 2 +- engine/apps/public_api/tests/test_schedule_export.py | 4 ++-- engine/apps/schedules/ical_utils.py | 8 ++++---- engine/apps/schedules/models/on_call_schedule.py | 4 ++-- engine/apps/slack/scenarios/slack_renderer.py | 4 ++-- engine/common/utils.py | 2 +- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index addbb371..9698c79b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,7 +29,7 @@ repos: files: ^dev/scripts - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 + rev: 7.0.0 hooks: - id: flake8 files: ^engine diff --git a/engine/apps/alerts/models/alert_group.py b/engine/apps/alerts/models/alert_group.py index 20c7408a..5b3d016b 100644 --- a/engine/apps/alerts/models/alert_group.py +++ b/engine/apps/alerts/models/alert_group.py @@ -1889,11 +1889,11 @@ class AlertGroup(AlertGroupSlackRenderingMixin, EscalationSnapshotMixin, models. result_log_report = list() for log_record in log_records_list: - if type(log_record) == AlertGroupLogRecord: + if type(log_record) is AlertGroupLogRecord: result_log_report.append(log_record.render_log_line_json()) - elif type(log_record) == UserNotificationPolicyLogRecord: + elif type(log_record) is UserNotificationPolicyLogRecord: result_log_report.append(log_record.rendered_notification_log_line_json) - elif type(log_record) == ResolutionNote: + elif type(log_record) is ResolutionNote: result_log_report.append(log_record.render_log_line_json()) return result_log_report diff --git a/engine/apps/api/tests/test_alert_receive_channel.py b/engine/apps/api/tests/test_alert_receive_channel.py index 1e70fb4c..bd2cf2ef 100644 --- a/engine/apps/api/tests/test_alert_receive_channel.py +++ b/engine/apps/api/tests/test_alert_receive_channel.py @@ -145,10 +145,10 @@ def test_list_alert_receive_channel_skip_pagination_for_grafana_alerting( assert response.status_code == status.HTTP_200_OK if should_be_unpaginated: - assert type(results) == list + assert type(results) is list assert len(results) > 0 else: - assert type(results["results"]) == list + assert type(results["results"]) is list assert len(results["results"]) > 0 diff --git a/engine/apps/api/views/alert_receive_channel.py b/engine/apps/api/views/alert_receive_channel.py index 871353bb..7bcdf89f 100644 --- a/engine/apps/api/views/alert_receive_channel.py +++ b/engine/apps/api/views/alert_receive_channel.py @@ -443,7 +443,7 @@ class AlertReceiveChannelView( if payload is None: return channel.alert_groups.last().alerts.first() else: - if type(payload) != dict: + if type(payload) is not dict: raise PreviewTemplateException("Payload must be a valid json object") # Build Alert and AlertGroup objects to pass to templater without saving them to db alert_group_to_template = AlertGroup(channel=channel) @@ -529,7 +529,7 @@ class AlertReceiveChannelView( try: instance.start_maintenance(mode, duration, request.user) except MaintenanceCouldNotBeStartedError as e: - if type(instance) == AlertReceiveChannel: + if type(instance) is AlertReceiveChannel: detail = {"alert_receive_channel_id": ["Already on maintenance"]} else: detail = str(e) diff --git a/engine/apps/base/tests/test_live_settings.py b/engine/apps/base/tests/test_live_settings.py index 965e2fb2..e58d7060 100644 --- a/engine/apps/base/tests/test_live_settings.py +++ b/engine/apps/base/tests/test_live_settings.py @@ -40,7 +40,7 @@ def test_multi_type_support(value): LiveSetting.objects.create(name="SOME_NEW_FEATURE_ENABLED", value=value) setting_value = LiveSetting.get_setting("SOME_NEW_FEATURE_ENABLED") - assert type(setting_value) == type(value) + assert type(setting_value) is type(value) assert setting_value == value diff --git a/engine/apps/public_api/tests/test_schedule_export.py b/engine/apps/public_api/tests/test_schedule_export.py index 9a5835f1..559a4a6c 100644 --- a/engine/apps/public_api/tests/test_schedule_export.py +++ b/engine/apps/public_api/tests/test_schedule_export.py @@ -78,7 +78,7 @@ def test_export_calendar(make_organization_and_user_with_token, make_user_for_or cal = Calendar.from_ical(response.data) - assert type(cal) == Calendar + assert type(cal) is Calendar # check there are events assert len(cal.subcomponents) > 0 for component in cal.walk(): @@ -112,7 +112,7 @@ def test_export_user_calendar(make_organization_and_user_with_token, make_schedu cal = Calendar.from_ical(response.data) - assert type(cal) == Calendar + assert type(cal) is Calendar assert cal.get("x-wr-calname") == "On-Call Schedule for {0}".format(user.username) assert cal.get("x-wr-timezone") == "UTC" assert cal.get("calscale") == "GREGORIAN" diff --git a/engine/apps/schedules/ical_utils.py b/engine/apps/schedules/ical_utils.py index 4cc1622e..488faf36 100644 --- a/engine/apps/schedules/ical_utils.py +++ b/engine/apps/schedules/ical_utils.py @@ -187,7 +187,7 @@ def list_of_oncall_shifts_from_ical( pytz_tz = pytz.timezone("UTC") return ( datetime.datetime.combine(e["start"], datetime.datetime.min.time(), tzinfo=pytz_tz) - if type(e["start"]) == datetime.date + if type(e["start"]) is datetime.date else e["start"] ) @@ -234,7 +234,7 @@ def get_shifts_dict( ) # Define on-call shift out of ical event that has the actual user if len(users) > 0 or with_empty_shifts: - if type(event[ICAL_DATETIME_START].dt) == datetime.date: + if type(event[ICAL_DATETIME_START].dt) is datetime.date: start = event[ICAL_DATETIME_START].dt end = event[ICAL_DATETIME_END].dt result_date.append( @@ -642,7 +642,7 @@ def is_icals_equal(first, second): def ical_date_to_datetime(date, tz, start): datetime_to_combine = datetime.time.min all_day = False - if type(date) == datetime.date: + if type(date) is datetime.date: all_day = True calendar_timezone_offset = datetime.datetime.now().astimezone(tz).utcoffset() date = datetime.datetime.combine(date, datetime_to_combine).astimezone(tz) - calendar_timezone_offset @@ -795,7 +795,7 @@ def start_end_with_respect_to_all_day(event: IcalEvent, calendar_tz): def event_start_end_all_day_with_respect_to_type(event: IcalEvent, calendar_tz): all_day = False - if type(event[ICAL_DATETIME_START].dt) == datetime.date: + if type(event[ICAL_DATETIME_START].dt) is datetime.date: start, end = start_end_with_respect_to_all_day(event, calendar_tz) all_day = True else: diff --git a/engine/apps/schedules/models/on_call_schedule.py b/engine/apps/schedules/models/on_call_schedule.py index 11e270e7..34c4f325 100644 --- a/engine/apps/schedules/models/on_call_schedule.py +++ b/engine/apps/schedules/models/on_call_schedule.py @@ -388,7 +388,7 @@ class OnCallSchedule(PolymorphicModel): events: ScheduleEvents = [] for shift in shifts: start = shift["start"] - all_day = type(start) == datetime.date + all_day = type(start) is datetime.date # fix confusing end date for all-day event end = shift["end"] - datetime.timedelta(days=1) if all_day else shift["end"] if all_day and all_day_datetime: @@ -513,7 +513,7 @@ class OnCallSchedule(PolymorphicModel): # check if event was ended or cancelled, update ical dtend = component.get(ICAL_DATETIME_END) dtend_datetime = dtend.dt if dtend else None - if dtend_datetime and type(dtend_datetime) == datetime.date: + if dtend_datetime and type(dtend_datetime) is datetime.date: # shift or overrides coming from ical calendars can be all day events, change to datetime dtend_datetime = datetime.datetime.combine( dtend.dt, datetime.datetime.min.time(), tzinfo=pytz.UTC diff --git a/engine/apps/slack/scenarios/slack_renderer.py b/engine/apps/slack/scenarios/slack_renderer.py index 853f7372..982671a7 100644 --- a/engine/apps/slack/scenarios/slack_renderer.py +++ b/engine/apps/slack/scenarios/slack_renderer.py @@ -22,9 +22,9 @@ class AlertGroupLogSlackRenderer: # get rendered logs result = "" for log_record in all_log_records: # list of AlertGroupLogRecord and UserNotificationPolicyLogRecord logs - if type(log_record) == AlertGroupLogRecord: + if type(log_record) is AlertGroupLogRecord: result += f"{log_record.rendered_incident_log_line(for_slack=True)}\n" - elif type(log_record) == UserNotificationPolicyLogRecord: + elif type(log_record) is UserNotificationPolicyLogRecord: result += f"{log_record.rendered_notification_log_line(for_slack=True)}\n" attachments.append( diff --git a/engine/common/utils.py b/engine/common/utils.py index 3350b08d..05141120 100644 --- a/engine/common/utils.py +++ b/engine/common/utils.py @@ -176,7 +176,7 @@ def isoformat_with_tz_suffix(value): def is_string_with_visible_characters(string): - return type(string) == str and not string.isspace() and not string == "" + return type(string) is str and not string.isspace() and not string == "" def str_or_backup(string, backup):