mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Add typing hints to github_tools with mypy enforcement (#771)
This commit is contained in:
@@ -9,11 +9,14 @@ Exceptions. See /LICENSE for license information.
|
||||
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from typing import Dict, Generator, Optional, Tuple
|
||||
|
||||
# https://pypi.org/project/gql/
|
||||
import gql
|
||||
import gql.transport.requests
|
||||
# gql is missing type annotations, so disable checking on around it.
|
||||
import gql # type: ignore
|
||||
import gql.transport.requests # type: ignore
|
||||
|
||||
_ENV_TOKEN = "GITHUB_ACCESS_TOKEN"
|
||||
|
||||
@@ -25,7 +28,9 @@ PAGINATION = """pageInfo {
|
||||
totalCount"""
|
||||
|
||||
|
||||
def add_access_token_arg(parser, permissions):
|
||||
def add_access_token_arg(
|
||||
parser: argparse.ArgumentParser, permissions: str
|
||||
) -> None:
|
||||
"""Adds a flag to set the access token."""
|
||||
access_token = os.environ.get(_ENV_TOKEN, default=None)
|
||||
parser.add_argument(
|
||||
@@ -42,7 +47,7 @@ def add_access_token_arg(parser, permissions):
|
||||
class Client(object):
|
||||
"""A GitHub GraphQL client."""
|
||||
|
||||
def __init__(self, parsed_args):
|
||||
def __init__(self, parsed_args: argparse.Namespace):
|
||||
"""Connects to GitHub."""
|
||||
transport = gql.transport.requests.RequestsHTTPTransport(
|
||||
url="https://api.github.com/graphql",
|
||||
@@ -50,11 +55,16 @@ class Client(object):
|
||||
)
|
||||
self._client = gql.Client(transport=transport)
|
||||
|
||||
def execute(self, query):
|
||||
def execute(self, query: str) -> Dict:
|
||||
"""Runs a query."""
|
||||
return self._client.execute(gql.gql(query))
|
||||
return self._client.execute(gql.gql(query)) # type: ignore
|
||||
|
||||
def execute_and_paginate(self, query, path, first_page=None):
|
||||
def execute_and_paginate(
|
||||
self,
|
||||
query: str,
|
||||
path: Tuple[str, ...],
|
||||
first_page: Optional[Dict] = None,
|
||||
) -> Generator[Dict, None, None]:
|
||||
"""Runs a query with pagination.
|
||||
|
||||
Arguments:
|
||||
|
||||
Reference in New Issue
Block a user