mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 13:31:06 +01:00
Fix ty errors for missing generic parameters (#7326)
Mostly these errors were around `dict` missing arguments, and they are almost always `[str, Any]`. But a real thorn here was `xml.etree.ElementTree.Element`. `ty` insists that this is a generic type, and indeed it appears to be one, or becoming one, in some python version. But it is not generic in python 3.12. So we are stuck in an unsolvable land where: - `ty` gives an error unless you write `[str]` on the type, because it thinks it is generic. - python3.12 gives an error if you do write `[str]` on the type, because it thinks it is not generic. Forcing `ty` to target exactly python 3.12 does not help. So I have just used a linter-ignore comment on that line.
This commit is contained in:
@@ -12,7 +12,7 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
import argparse
|
||||
import os
|
||||
from collections.abc import Generator
|
||||
from typing import Optional, cast
|
||||
from typing import Any, Optional, cast
|
||||
|
||||
# https://pypi.org/project/gql/
|
||||
import gql
|
||||
@@ -56,11 +56,11 @@ class Client:
|
||||
self._client = gql.Client(transport=transport)
|
||||
|
||||
def execute(
|
||||
self, query: str, variable_values: Optional[dict] = None
|
||||
) -> dict:
|
||||
self, query: str, variable_values: Optional[dict[str, Any]] = None
|
||||
) -> dict[str, Any]:
|
||||
"""Runs a query."""
|
||||
return cast(
|
||||
dict,
|
||||
dict[str, Any],
|
||||
self._client.execute(
|
||||
gql.gql(query), variable_values=variable_values
|
||||
),
|
||||
@@ -70,8 +70,8 @@ class Client:
|
||||
self,
|
||||
query: str,
|
||||
path: tuple[str, ...],
|
||||
first_page: Optional[dict] = None,
|
||||
) -> Generator[dict, None, None]:
|
||||
first_page: Optional[dict[str, Any]] = None,
|
||||
) -> Generator[dict[str, Any], None, None]:
|
||||
"""Runs a query with pagination.
|
||||
|
||||
Arguments:
|
||||
|
||||
@@ -129,7 +129,7 @@ class _Comment:
|
||||
self.body = body
|
||||
|
||||
@staticmethod
|
||||
def from_raw_comment(raw_comment: dict) -> "_Comment":
|
||||
def from_raw_comment(raw_comment: dict[str, Any]) -> "_Comment":
|
||||
"""Creates the comment from a raw comment dict."""
|
||||
return _Comment(
|
||||
raw_comment["author"]["login"],
|
||||
@@ -176,7 +176,7 @@ class _Comment:
|
||||
class _PRComment(_Comment):
|
||||
"""A comment on the top-level PR."""
|
||||
|
||||
def __init__(self, raw_comment: dict):
|
||||
def __init__(self, raw_comment: dict[str, Any]):
|
||||
super().__init__(
|
||||
raw_comment["author"]["login"],
|
||||
raw_comment["createdAt"],
|
||||
@@ -195,7 +195,7 @@ class _PRComment(_Comment):
|
||||
class _Thread:
|
||||
"""A review thread on a line of code."""
|
||||
|
||||
def __init__(self, parsed_args: argparse.Namespace, thread: dict):
|
||||
def __init__(self, parsed_args: argparse.Namespace, thread: dict[str, Any]):
|
||||
self.is_resolved: bool = thread["isResolved"]
|
||||
|
||||
comments = thread["comments"]["nodes"]
|
||||
@@ -347,7 +347,7 @@ def _query(
|
||||
def _accumulate_pr_comment(
|
||||
parsed_args: argparse.Namespace,
|
||||
comments: list[_PRComment],
|
||||
raw_comment: dict,
|
||||
raw_comment: dict[str, Any],
|
||||
) -> None:
|
||||
"""Collects top-level comments and reviews."""
|
||||
# Elide reviews that have no top-level comment body.
|
||||
@@ -358,7 +358,7 @@ def _accumulate_pr_comment(
|
||||
def _accumulate_thread(
|
||||
parsed_args: argparse.Namespace,
|
||||
threads_by_path: dict[str, list[_Thread]],
|
||||
raw_thread: dict,
|
||||
raw_thread: dict[str, Any],
|
||||
) -> None:
|
||||
"""Adds threads to threads_by_path for later sorting."""
|
||||
thread = _Thread(parsed_args, raw_thread)
|
||||
@@ -387,10 +387,10 @@ def _accumulate_thread(
|
||||
|
||||
def _paginate(
|
||||
field_name: str,
|
||||
accumulator: Callable[[argparse.Namespace, Any, dict], None],
|
||||
accumulator: Callable[[argparse.Namespace, Any, dict[str, Any]], None],
|
||||
parsed_args: argparse.Namespace,
|
||||
client: github_helpers.Client,
|
||||
main_result: dict,
|
||||
main_result: dict[str, Any],
|
||||
output: Any,
|
||||
) -> None:
|
||||
"""Paginates through the given field_name, accumulating results."""
|
||||
|
||||
Reference in New Issue
Block a user