Browse Source

ref: use dict instead of OrderedDict since sentry is >python3.6 (#39695)

partially automated (especially the fixtures) also via `\(([^]+),
(.*)\),$` -> `\1: \2,`
anthony sottile 2 years ago
parent
commit
286bf2ae7e

+ 57 - 189
fixtures/bitbucket.py

@@ -1,5 +1,3 @@
-from collections import OrderedDict
-
 COMPARE_COMMITS_EXAMPLE = b"""{
 "pagelen": 30,
  "values":
@@ -276,194 +274,64 @@ REPO = {
     "website": "",
     "has_wiki": True,
     "description": "",
-    "links": OrderedDict(
-        [
-            (
-                "watchers",
-                OrderedDict(
-                    [
-                        (
-                            "href",
-                            "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/watchers",
-                        )
-                    ]
-                ),
-            ),
-            (
-                "branches",
-                OrderedDict(
-                    [
-                        (
-                            "href",
-                            "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/refs/branches",
-                        )
-                    ]
-                ),
-            ),
-            (
-                "tags",
-                OrderedDict(
-                    [
-                        (
-                            "href",
-                            "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/refs/tags",
-                        )
-                    ]
-                ),
-            ),
-            (
-                "commits",
-                OrderedDict(
-                    [
-                        (
-                            "href",
-                            "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/commits",
-                        )
-                    ]
-                ),
-            ),
-            (
-                "clone",
-                [
-                    OrderedDict(
-                        [
-                            (
-                                "href",
-                                "https://laurynsentry@bitbucket.org/laurynsentry/helloworld.git",
-                            ),
-                            ("name", "https"),
-                        ]
-                    ),
-                    OrderedDict(
-                        [
-                            ("href", "git@bitbucket.org:laurynsentry/helloworld.git"),
-                            ("name", "ssh"),
-                        ]
-                    ),
-                ],
-            ),
-            (
-                "self",
-                OrderedDict(
-                    [
-                        (
-                            "href",
-                            "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld",
-                        )
-                    ]
-                ),
-            ),
-            (
-                "source",
-                OrderedDict(
-                    [
-                        (
-                            "href",
-                            "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/src",
-                        )
-                    ]
-                ),
-            ),
-            ("html", OrderedDict([("href", "https://bitbucket.org/laurynsentry/helloworld")])),
-            (
-                "avatar",
-                OrderedDict(
-                    [
-                        (
-                            "href",
-                            "https://bytebucket.org/ravatar/%7B2a47ac11-098a-4054-8496-193754cae14b%7D?ts=default",
-                        )
-                    ]
-                ),
-            ),
-            (
-                "hooks",
-                OrderedDict(
-                    [
-                        (
-                            "href",
-                            "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/hooks",
-                        )
-                    ]
-                ),
-            ),
-            (
-                "forks",
-                OrderedDict(
-                    [
-                        (
-                            "href",
-                            "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/forks",
-                        )
-                    ]
-                ),
-            ),
-            (
-                "downloads",
-                OrderedDict(
-                    [
-                        (
-                            "href",
-                            "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/downloads",
-                        )
-                    ]
-                ),
-            ),
-            (
-                "issues",
-                OrderedDict(
-                    [
-                        (
-                            "href",
-                            "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/issues",
-                        )
-                    ]
-                ),
-            ),
-            (
-                "pullrequests",
-                OrderedDict(
-                    [
-                        (
-                            "href",
-                            "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/pullrequests",
-                        )
-                    ]
-                ),
-            ),
-        ]
-    ),
+    "links": {
+        "watchers": {
+            "href": "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/watchers"
+        },
+        "branches": {
+            "href": "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/refs/branches"
+        },
+        "tags": {
+            "href": "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/refs/tags"
+        },
+        "commits": {
+            "href": "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/commits"
+        },
+        "clone": [
+            {
+                "href": "https://laurynsentry@bitbucket.org/laurynsentry/helloworld.git",
+                "name": "https",
+            },
+            {"href": "git@bitbucket.org:laurynsentry/helloworld.git", "name": "ssh"},
+        ],
+        "self": {"href": "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld"},
+        "source": {
+            "href": "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/src"
+        },
+        "html": {"href": "https://bitbucket.org/laurynsentry/helloworld"},
+        "avatar": {
+            "href": "https://bytebucket.org/ravatar/%7B2a47ac11-098a-4054-8496-193754cae14b%7D?ts=default"
+        },
+        "hooks": {
+            "href": "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/hooks"
+        },
+        "forks": {
+            "href": "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/forks"
+        },
+        "downloads": {
+            "href": "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/downloads"
+        },
+        "issues": {
+            "href": "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/issues"
+        },
+        "pullrequests": {
+            "href": "https://api.bitbucket.org/2.0/repositories/laurynsentry/helloworld/pullrequests"
+        },
+    },
     "created_on": "2018-05-14T23:53:37.377674+00:00",
     "full_name": "laurynsentry/helloworld",
-    "owner": OrderedDict(
-        [
-            ("username", "laurynsentry"),
-            ("display_name", "Lauryn Brown"),
-            ("account_id", "5a00066393915e620920e0ae"),
-            (
-                "links",
-                OrderedDict(
-                    [
-                        (
-                            "self",
-                            OrderedDict(
-                                [("href", "https://api.bitbucket.org/2.0/users/laurynsentry")]
-                            ),
-                        ),
-                        ("html", OrderedDict([("href", "https://bitbucket.org/laurynsentry/")])),
-                        (
-                            "avatar",
-                            OrderedDict(
-                                [("href", "https://bitbucket.org/account/laurynsentry/avatar/")]
-                            ),
-                        ),
-                    ]
-                ),
-            ),
-            ("type", "user"),
-            ("uuid", "{e50a27fe-0686-4d75-ba44-d27608bbb718}"),
-        ]
-    ),
+    "owner": {
+        "username": "laurynsentry",
+        "display_name": "Lauryn Brown",
+        "account_id": "5a00066393915e620920e0ae",
+        "links": {
+            "self": {"href": "https://api.bitbucket.org/2.0/users/laurynsentry"},
+            "html": {"href": "https://bitbucket.org/laurynsentry/"},
+            "avatar": {"href": "https://bitbucket.org/account/laurynsentry/avatar/"},
+        },
+        "type": "user",
+        "uuid": "{e50a27fe-0686-4d75-ba44-d27608bbb718}",
+    },
     "has_issues": True,
     "slug": "helloworld",
     "is_private": False,
@@ -472,7 +340,7 @@ REPO = {
     "language": "",
     "fork_policy": "allow_forks",
     "uuid": "{2a47ac11-098a-4054-8496-193754cae14b}",
-    "mainbranch": OrderedDict([("type", "branch"), ("name", "master")]),
+    "mainbranch": {"type": "branch", "name": "master"},
     "updated_on": "2018-05-30T18:21:08.780363+00:00",
     "type": "repository",
 }

+ 15 - 66
fixtures/bitbucket_server.py

@@ -1,5 +1,3 @@
-from collections import OrderedDict
-
 EXAMPLE_PRIVATE_KEY = """-----BEGIN RSA PRIVATE KEY-----
 MIICWwIBAAKBgQC1cd9t8sA03awggLiX2gjZxyvOVUPJksLly1E662tttTeR3Wm9
 eo6onNeI8HRD+O4wubUp4h4Chc7DtLDmFEPhUZ8Qkwztiifm99Xo3s0nUq4Pygp5
@@ -113,73 +111,24 @@ REPO = {
     "state": "AVAILABLE",
     "statusMessage": "Available",
     "forkable": True,
-    "project": OrderedDict(
-        [
-            ("key", "laurynsentry"),
-            ("id", 75),
-            ("name", "laurynsentry"),
-            ("description", ""),
-            ("public", False),
-            ("type", "Normal"),
-            (
-                "links",
-                OrderedDict(
-                    [
-                        (
-                            "self",
-                            OrderedDict(
-                                [("href", "https://bitbucket.example.org/projects/laurynsentry")]
-                            ),
-                        )
-                    ]
-                ),
-            ),
-        ]
-    ),
+    "project": {
+        "key": "laurynsentry",
+        "id": 75,
+        "name": "laurynsentry",
+        "description": "",
+        "public": False,
+        "type": "Normal",
+        "links": {"self": {"href": "https://bitbucket.example.org/projects/laurynsentry"}},
+    },
     "public": False,
-    "links": OrderedDict(
-        [
-            (
-                "clone",
-                OrderedDict(
-                    [
-                        OrderedDict(
-                            [
-                                (
-                                    "href",
-                                    "https://bitbucket.example.org/scm/laurynsentry/helloworld.git",
-                                ),
-                                ("name", "http"),
-                            ]
-                        ),
-                        OrderedDict(
-                            [
-                                (
-                                    "href",
-                                    "ssh://git@bitbucket.example.org:7999/laurynsentry/helloworld.git",
-                                ),
-                                ("name", "ssh"),
-                            ]
-                        ),
-                    ]
-                ),
-            ),
-            (
-                "self",
-                OrderedDict(
-                    [
-                        (
-                            "href",
-                            "https://bitbucket.example.org/projects/laurynsentry/repos/helloworld/browse",
-                        )
-                    ]
-                ),
-            ),
-        ]
-    ),
+    "links": {
+        "clone": {"href": "name"},
+        "self": {
+            "href": "https://bitbucket.example.org/projects/laurynsentry/repos/helloworld/browse"
+        },
+    },
 }
 
-
 COMPARE_COMMITS_WITH_PAGES_1_2_EXAMPLE = {
     "values": [
         {

+ 1 - 3
src/sentry/api/endpoints/monitor_stats.py

@@ -1,5 +1,3 @@
-from collections import OrderedDict
-
 from rest_framework.request import Request
 from rest_framework.response import Response
 
@@ -15,7 +13,7 @@ class MonitorStatsEndpoint(MonitorEndpoint, StatsMixin):
     def get(self, request: Request, project, monitor) -> Response:
         args = self._parse_args(request)
 
-        stats = OrderedDict()
+        stats = {}
         current = tsdb.normalize_to_epoch(args["start"], args["rollup"])
         end = tsdb.normalize_to_epoch(args["end"], args["rollup"])
         while current <= end:

+ 1 - 3
src/sentry/api/endpoints/project_servicehook_stats.py

@@ -1,5 +1,3 @@
-from collections import OrderedDict
-
 from rest_framework.request import Request
 from rest_framework.response import Response
 
@@ -20,7 +18,7 @@ class ProjectServiceHookStatsEndpoint(ProjectEndpoint, StatsMixin):
 
         stat_args = self._parse_args(request)
 
-        stats = OrderedDict()
+        stats = {}
         for model, name in ((tsdb.models.servicehook_fired, "total"),):
             result = tsdb.get_range(model=model, keys=[hook.id], **stat_args)[hook.id]
             for ts, count in result:

+ 9 - 9
src/sentry/api/validators/monitor.py

@@ -1,5 +1,3 @@
-from collections import OrderedDict
-
 from croniter import croniter
 from django.core.exceptions import ValidationError
 from rest_framework import serializers
@@ -8,15 +6,17 @@ from sentry.api.fields.empty_integer import EmptyIntegerField
 from sentry.api.serializers.rest_framework.project import ProjectField
 from sentry.models import MonitorStatus, MonitorType, ScheduleType
 
-SCHEDULE_TYPES = OrderedDict(
-    [("crontab", ScheduleType.CRONTAB), ("interval", ScheduleType.INTERVAL)]
-)
+SCHEDULE_TYPES = {
+    "crontab": ScheduleType.CRONTAB,
+    "interval": ScheduleType.INTERVAL,
+}
 
-MONITOR_TYPES = OrderedDict([("cron_job", MonitorType.CRON_JOB)])
+MONITOR_TYPES = {"cron_job": MonitorType.CRON_JOB}
 
-MONITOR_STATUSES = OrderedDict(
-    [("active", MonitorStatus.ACTIVE), ("disabled", MonitorStatus.DISABLED)]
-)
+MONITOR_STATUSES = {
+    "active": MonitorStatus.ACTIVE,
+    "disabled": MonitorStatus.DISABLED,
+}
 
 INTERVAL_NAMES = ("year", "month", "week", "day", "hour", "minute")
 

+ 2 - 2
src/sentry/apidocs/spectacular_ports.py

@@ -3,7 +3,7 @@
 import collections
 import inspect
 import typing
-from collections import OrderedDict, defaultdict
+from collections import defaultdict
 from enum import Enum
 from typing import Any, Literal, Union
 from typing import get_type_hints as _get_type_hints
@@ -77,7 +77,7 @@ def resolve_type_hint(hint) -> Any:
             max_length=len(args),
             min_length=len(args),
         )
-    elif origin is dict or origin is defaultdict or origin is OrderedDict:
+    elif origin is dict or origin is defaultdict:
         schema = build_basic_type(OpenApiTypes.OBJECT)
         if args and args[1] is not typing.Any:
             schema["additionalProperties"] = resolve_type_hint(args[1])

+ 12 - 12
src/sentry/constants.py

@@ -5,7 +5,7 @@ web-server
 
 import logging
 import os.path
-from collections import OrderedDict, namedtuple
+from collections import namedtuple
 from datetime import timedelta
 from typing import Dict, List, Optional, Sequence, Tuple, cast
 
@@ -40,18 +40,18 @@ COMMIT_RANGE_DELIMITER = ".."
 # semver constants
 SEMVER_FAKE_PACKAGE = "__sentry_fake__"
 
-SORT_OPTIONS = OrderedDict(
-    (
-        ("priority", _("Priority")),
-        ("date", _("Last Seen")),
-        ("new", _("First Seen")),
-        ("freq", _("Frequency")),
-    )
-)
+SORT_OPTIONS = {
+    "priority": _("Priority"),
+    "date": _("Last Seen"),
+    "new": _("First Seen"),
+    "freq": _("Frequency"),
+}
 
-SEARCH_SORT_OPTIONS = OrderedDict(
-    (("score", _("Score")), ("date", _("Last Seen")), ("new", _("First Seen")))
-)
+SEARCH_SORT_OPTIONS = {
+    "score": _("Score"),
+    "date": _("Last Seen"),
+    "new": _("First Seen"),
+}
 
 # XXX: Deprecated: use GroupStatus instead
 STATUS_UNRESOLVED = 0

+ 3 - 3
src/sentry/digests/utils.py

@@ -1,6 +1,6 @@
 from __future__ import annotations
 
-from collections import Counter, OrderedDict, defaultdict
+from collections import Counter, defaultdict
 from datetime import datetime
 from typing import Any
 from typing import Counter as CounterType
@@ -96,9 +96,9 @@ def get_event_from_groups_in_digest(digest: Digest) -> Iterable[Event]:
 
 def build_custom_digest(original_digest: Digest, events: Iterable[Event]) -> Digest:
     """Given a digest and a set of events, filter the digest to only records that include the events."""
-    user_digest: Digest = OrderedDict()
+    user_digest: Digest = {}
     for rule, rule_groups in original_digest.items():
-        user_rule_groups = OrderedDict()
+        user_rule_groups = {}
         for group, group_records in rule_groups.items():
             user_group_records = [
                 record for record in group_records if record.value.event in events

+ 1 - 3
src/sentry/eventstore/models.py

@@ -2,7 +2,6 @@ from __future__ import annotations
 
 import abc
 import string
-from collections import OrderedDict
 from copy import deepcopy
 from datetime import datetime
 from hashlib import md5
@@ -504,8 +503,7 @@ class BaseEvent(metaclass=abc.ABCMeta):
 
     def as_dict(self) -> Mapping[str, Any]:
         """Returns the data in normalized form for external consumers."""
-        # We use a OrderedDict to keep elements ordered for a potential JSON serializer
-        data: MutableMapping[str, Any] = OrderedDict()
+        data: MutableMapping[str, Any] = {}
         data["event_id"] = self.event_id
         data["project"] = self.project_id
         data["release"] = self.release

+ 1 - 3
src/sentry/integrations/vsts/issues.py

@@ -1,4 +1,3 @@
-from collections import OrderedDict
 from typing import TYPE_CHECKING, Any, Mapping, MutableMapping, Optional, Sequence, Set, Tuple
 
 from django.urls import reverse
@@ -79,8 +78,7 @@ class VstsIssueSync(IssueSyncMixin):  # type: ignore
         except (ApiError, ApiUnauthorized, KeyError) as e:
             raise self.raise_error(e)
 
-        # we want to maintain ordering of the items
-        item_type_map = OrderedDict()
+        item_type_map = {}
         for item in item_categories:
             for item_type_object in item["workItemTypes"]:
                 # the type is the last part of the url

Some files were not shown because too many files changed in this diff