Run mypy on the scripts directory in CI (#8133)

This commit is contained in:
Alex Waygood
2022-06-22 14:13:38 +01:00
committed by GitHub
parent 89f4dee452
commit a527bf27d5
3 changed files with 41 additions and 16 deletions

View File

@@ -139,9 +139,11 @@ def main() -> None:
# The importlib.metadata module is used for projects whose name is different
# from the runtime Python package name (example: PyYAML/yaml)
if sys.version_info >= (3, 8):
packages = [name for name in distribution(project).read_text("top_level.txt").split() if not name.startswith("_")]
if len(packages) == 1:
package = packages[0]
dist = distribution(project).read_text("top_level.txt")
if dist is not None:
packages = [name for name in dist.split() if not name.startswith("_")]
if len(packages) == 1:
package = packages[0]
print(f'Using detected package "{package}" for project "{project}"', file=sys.stderr)
print("Suggestion: Try again with --package argument if that's not what you wanted", file=sys.stderr)

View File

@@ -16,7 +16,7 @@ import urllib.parse
import zipfile
from dataclasses import dataclass
from pathlib import Path
from typing import Any
from typing import Any, TypeVar
import aiohttp
import packaging.specifiers
@@ -24,9 +24,11 @@ import packaging.version
import tomli
import tomlkit
ActionLevelSelf = TypeVar("ActionLevelSelf", bound="ActionLevel")
class ActionLevel(enum.IntEnum):
def __new__(cls, value: int, doc: str):
def __new__(cls: type[ActionLevelSelf], value: int, doc: str) -> ActionLevelSelf:
member = int.__new__(cls, value)
member._value_ = value
member.__doc__ = doc
@@ -191,7 +193,7 @@ TYPESHED_OWNER = "python"
@functools.lru_cache()
def get_origin_owner():
def get_origin_owner() -> str:
output = subprocess.check_output(["git", "remote", "get-url", "origin"], text=True)
match = re.search(r"(git@github.com:|https://github.com/)(?P<owner>[^/]+)/(?P<repo>[^/]+).git", output)
assert match is not None
@@ -199,7 +201,7 @@ def get_origin_owner():
return match.group("owner")
async def create_or_update_pull_request(*, title: str, body: str, branch_name: str, session: aiohttp.ClientSession):
async def create_or_update_pull_request(*, title: str, body: str, branch_name: str, session: aiohttp.ClientSession) -> None:
secret = os.environ["GITHUB_TOKEN"]
if secret.startswith("ghp"):
auth = f"token {secret}"