Created
June 10, 2026 20:28
-
-
Save mypy-play/3eb431432e37881ea7500d3d3ebc903f to your computer and use it in GitHub Desktop.
Shared via mypy Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections.abc import Callable | |
| from typing import Protocol, TypeVar | |
| class TGCStatsInfo(Protocol): | |
| gen: int | |
| iid: int | |
| class TInstantMsg(Protocol): | |
| type: str | |
| name: str | |
| class PerfettoTrackState: | |
| def __init__(self) -> None: | |
| self._pids: set[int] = set() | |
| self._tids: set[tuple[int, int]] = set() | |
| self._cmdlines: dict[int, list[str]] = {} | |
| self._counter_tracks: dict[tuple[int, int, int, str], int] = {} | |
| self._counter_counter = 0 | |
| def convert_item_to_perfetto_packets( | |
| pid: int, | |
| item: TGCStatsInfo, | |
| state: PerfettoTrackState, | |
| sequence_id: int, | |
| ) -> tuple[list[bytes], list[bytes]]: | |
| return ([b""], [b""]) | |
| def convert_instant_to_perfetto_packet( | |
| pid: int, | |
| item: TInstantMsg, | |
| state: PerfettoTrackState, | |
| sequence_id: int, | |
| ) -> tuple[list[bytes], list[bytes]]: | |
| return ([b""], [b""]) | |
| TItem = TypeVar("TItem", TGCStatsInfo, TInstantMsg) | |
| ConvertFn = Callable[ | |
| [int, TItem, PerfettoTrackState, int], | |
| tuple[list[bytes], list[bytes]], | |
| ] | |
| class X: | |
| def _enqueue( | |
| self, | |
| pid: int, | |
| item: TItem, | |
| convert: ConvertFn, | |
| ) -> None: | |
| descriptors, packets = convert(pid, item, PerfettoTrackState(), 1) | |
| assert descriptors != packets | |
| def add_event(self, pid: int, item: TGCStatsInfo) -> None: | |
| self._enqueue(pid, item, convert_item_to_perfetto_packets) | |
| def add_instant_event(self, pid: int, item: TInstantMsg) -> None: | |
| self._enqueue(pid, item, convert_instant_to_perfetto_packet) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment