Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Removing TypedDict hack we had to use it early #29511

Merged
merged 3 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 deletions src/sentry/api/endpoints/organization_events_trace.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
from collections import OrderedDict, defaultdict, deque
from typing import (
TYPE_CHECKING,
Any,
Callable,
Deque,
Expand All @@ -13,6 +12,7 @@
Sequence,
Set,
Tuple,
TypedDict,
TypeVar,
cast,
)
Expand All @@ -36,14 +36,6 @@
logger: logging.Logger = logging.getLogger(__name__)
MAX_TRACE_SIZE: int = 100

# TODO(3.8): This is a hack so we can get TypedDicts before 3.8
if TYPE_CHECKING:
from mypy_extensions import TypedDict
else:

def TypedDict(*args, **kwargs):
pass


_T = TypeVar("_T")
NodeSpans = List[Dict[str, Any]]
Expand Down Expand Up @@ -77,18 +69,18 @@ def TypedDict(*args, **kwargs):
"project": str,
},
)
TraceError = TypedDict(
"TraceError",
{
"event_id": str,
"issue_id": int,
"span": str,
"project_id": int,
"project_slug": str,
"title": str,
"level": str,
},
)


class TraceError(TypedDict):
event_id: str
issue_id: int
span: str
project_id: int
project_slug: str
title: str
level: str


LightResponse = TypedDict(
"LightResponse",
{
Expand Down
44 changes: 14 additions & 30 deletions src/sentry/grouping/result.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,25 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Union
from typing import Any, Dict, List, Optional, Sequence, TypedDict, Union

from sentry.utils.safe import get_path, safe_execute, set_path

# TODO(3.8): This is a hack so we can get TypedDicts before 3.8
if TYPE_CHECKING:
from mypy_extensions import TypedDict
else:

def TypedDict(*args, **kwargs):
pass


EventData = Dict[str, Any]
EventMetadata = Dict[str, Any]


TreeLabelPart = TypedDict(
"TreeLabelPart",
{
"function": str,
"package": str,
"is_sentinel": bool,
"is_prefix": bool,
"datapath": Sequence[Union[str, int]],
},
)

StrippedTreeLabelPart = TypedDict(
"StrippedTreeLabelPart",
{
"function": str,
"package": str,
"is_sentinel": bool,
"is_prefix": bool,
},
)
class TreeLabelPart(TypedDict):
function: str
package: str
is_sentinel: bool
is_prefix: bool
datapath: Sequence[Union[str, int]]


class StrippedTreeLabelPart(TypedDict):
function: str
package: str
is_sentinel: bool
is_prefix: bool


TreeLabel = Sequence[TreeLabelPart]
Expand Down
17 changes: 5 additions & 12 deletions src/sentry/integrations/slack/message_builder/base/block.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
from abc import ABC
from typing import TYPE_CHECKING, Any, Dict, List, MutableMapping, Optional, Sequence, Tuple
from typing import Any, Dict, List, MutableMapping, Optional, Sequence, Tuple, TypedDict

from sentry.integrations.slack.message_builder import SlackBlock, SlackBody
from sentry.integrations.slack.message_builder.base.base import SlackMessageBuilder

# TODO(3.8): This is a hack so we can get TypedDicts before 3.8
if TYPE_CHECKING:
from mypy_extensions import TypedDict
else:

def TypedDict(*args, **kwargs):
pass


class BlockSlackMessageBuilder(SlackMessageBuilder, ABC):
@staticmethod
Expand Down Expand Up @@ -46,9 +38,10 @@ def get_divider() -> SlackBlock:

@staticmethod
def get_action_block(actions: Sequence[Tuple[str, Optional[str], str]]) -> SlackBlock:
SlackBlockType = TypedDict(
"SlackBlockType", {"type": str, "elements": List[Dict[str, Any]]}
)
class SlackBlockType(TypedDict):
type: str
elements: List[Dict[str, Any]]

action_block: SlackBlockType = {"type": "actions", "elements": []}
for text, url, value in actions:
button = {
Expand Down
40 changes: 14 additions & 26 deletions src/sentry/spans/grouping/strategy/base.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@
import re
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Sequence
from typing import Any, Callable, Dict, Optional, Sequence, TypedDict
from urllib.parse import urlparse

from sentry.spans.grouping.utils import Hash, parse_fingerprint_var

# TODO(3.8): This is a hack so we can get TypedDicts before 3.8
if TYPE_CHECKING:
from mypy_extensions import TypedDict
else:

def TypedDict(*args, **kwargs):
pass


Span = TypedDict(
"Span",
{
"trace_id": str,
"parent_span_id": str,
"span_id": str,
"start_timestamp": float,
"timestamp": float,
"same_process_as_parent": bool,
"op": str,
"description": Optional[str],
"fingerprint": Optional[Sequence[str]],
"tags": Optional[Any],
"data": Optional[Any],
},
)

class Span(TypedDict):
trace_id: str
parent_span_id: str
span_id: str
start_timestamp: float
timestamp: float
same_process_as_parent: bool
op: str
description: Optional[str]
fingerprint: Optional[Sequence[str]]
tags: Optional[Any]
data: Optional[Any]


# A callable strategy is a callable that when given a span, it tries to
Expand Down