Skip to content

Commit

Permalink
chore: pyupgrade --py39-plus
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Nov 4, 2024
1 parent 74597af commit d1a7029
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/scriv/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def read_file_value(self, file_name: str) -> str:
return value


def convert_list(val: str) -> List[str]:
def convert_list(val: str) -> list[str]:
"""
Convert a string value from a config into a list of strings.
Expand Down
2 changes: 1 addition & 1 deletion src/scriv/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# When collecting changelog fragments, we group them by their category into
# Sections. A SectionDict maps category names to a list of the paragraphs in
# that section. For projects not using categories, the key will be None.
SectionDict = Dict[Optional[str], List[str]]
SectionDict = dict[Optional[str], list[str]]


class FormatTools(abc.ABC):
Expand Down
13 changes: 7 additions & 6 deletions src/scriv/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import logging
import os
from typing import Any, Dict, Iterable
from typing import Any, Dict
from collections.abc import Iterable

import requests

Expand All @@ -24,7 +25,7 @@ def check_ok(resp):
resp.raise_for_status()


def auth_headers() -> Dict[str, str]:
def auth_headers() -> dict[str, str]:
"""
Get the authorization headers needed for GitHub.
Expand All @@ -37,7 +38,7 @@ def auth_headers() -> Dict[str, str]:
return headers


def github_paginated(url: str) -> Iterable[Dict[str, Any]]:
def github_paginated(url: str) -> Iterable[dict[str, Any]]:
"""
Get all the results from a paginated GitHub url.
"""
Expand All @@ -54,7 +55,7 @@ def github_paginated(url: str) -> Iterable[Dict[str, Any]]:
RELEASES_URL = "https://api.github.com/repos/{repo}/releases"


def get_releases(repo: str) -> Dict[str, Dict[str, Any]]:
def get_releases(repo: str) -> dict[str, dict[str, Any]]:
"""
Get all the releases from a name/project repo.
Expand All @@ -66,7 +67,7 @@ def get_releases(repo: str) -> Dict[str, Dict[str, Any]]:
return releases


def create_release(repo: str, release_data: Dict[str, Any]) -> None:
def create_release(repo: str, release_data: dict[str, Any]) -> None:
"""
Create a GitHub release.
Expand All @@ -89,7 +90,7 @@ def create_release(repo: str, release_data: Dict[str, Any]) -> None:


def update_release(
release: Dict[str, Any], release_data: Dict[str, Any]
release: dict[str, Any], release_data: dict[str, Any]
) -> None:
"""
Update a GitHub release.
Expand Down
2 changes: 1 addition & 1 deletion src/scriv/gitinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def git_rm(filename: Path) -> None:
sys.exit(ret)


def get_github_repos() -> Set[str]:
def get_github_repos() -> set[str]:
"""
Find the GitHub name/repos for this project.
Expand Down
2 changes: 1 addition & 1 deletion src/scriv/linkcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import concurrent.futures
import logging
from typing import Iterable
from collections.abc import Iterable

import markdown_it
import requests
Expand Down
3 changes: 2 additions & 1 deletion src/scriv/literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import ast
import configparser
import os.path
from typing import Any, MutableMapping, Optional
from typing import Any, Optional
from collections.abc import MutableMapping

from .exceptions import ScrivException
from .optional import tomllib, yaml
Expand Down
7 changes: 4 additions & 3 deletions src/scriv/scriv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import re
import textwrap
from pathlib import Path
from typing import Iterable, List, Optional
from typing import List, Optional
from collections.abc import Iterable

import jinja2

Expand Down Expand Up @@ -37,7 +38,7 @@ def new_fragment(self) -> Fragment:
content=_new_fragment_content(self.config),
)

def fragments_to_combine(self) -> List[Fragment]:
def fragments_to_combine(self) -> list[Fragment]:
"""Get the list of fragments to combine."""
return [Fragment(path=path) for path in _files_to_combine(self.config)]

Expand Down Expand Up @@ -94,7 +95,7 @@ def _new_fragment_content(config: Config) -> str:
).render(config=config)


def _files_to_combine(config: Config) -> List[Path]:
def _files_to_combine(config: Config) -> list[Path]:
"""
Find all the fragment file paths to be combined.
Expand Down
6 changes: 3 additions & 3 deletions src/scriv/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from typing import List, Tuple, Union

# The return value of run_command.
CmdResult = Tuple[bool, str]
CmdResult = tuple[bool, str]

logger = logging.getLogger(__name__)


def run_command(cmd: Union[str, List[str]]) -> CmdResult:
def run_command(cmd: Union[str, list[str]]) -> CmdResult:
"""
Run a command line (with no shell).
Expand All @@ -38,7 +38,7 @@ def run_command(cmd: Union[str, List[str]]) -> CmdResult:
return proc.returncode == 0, output


def run_simple_command(cmd: Union[str, List[str]]) -> str:
def run_simple_command(cmd: Union[str, list[str]]) -> str:
"""
Run a command and return its output, or "" if it fails.
"""
Expand Down
11 changes: 6 additions & 5 deletions src/scriv/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import logging
import re
import sys
from typing import Dict, Optional, Sequence, Tuple, TypeVar
from typing import Dict, Optional, Tuple, TypeVar
from collections.abc import Sequence

import click_log

Expand All @@ -18,8 +19,8 @@


def order_dict(
d: Dict[Optional[K], T], keys: Sequence[Optional[K]]
) -> Dict[Optional[K], T]:
d: dict[K | None, T], keys: Sequence[K | None]
) -> dict[K | None, T]:
"""
Produce an OrderedDict of `d`, but with the keys in `keys` order.
Expand All @@ -40,7 +41,7 @@ def order_dict(
return with_order


def partition_lines(text: str, marker: str) -> Tuple[str, str, str]:
def partition_lines(text: str, marker: str) -> tuple[str, str, str]:
"""
Split `text` by lines, similar to str.partition.
Expand Down Expand Up @@ -102,7 +103,7 @@ def __hash__(self):
return hash(self.vtext.lstrip("v"))

@classmethod
def from_text(cls, text: str) -> Optional[Version]:
def from_text(cls, text: str) -> Version | None:
"""Find a version number in a text string."""
m = re.search(VERSION_REGEX, text)
if m:
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import traceback
from pathlib import Path
from typing import Iterable
from collections.abc import Iterable

import pytest
import responses
Expand Down
15 changes: 8 additions & 7 deletions tests/faker.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Fake implementations of some of our external information sources."""

import shlex
from typing import Callable, Dict, Iterable, List, Optional, Set, Tuple
from typing import Callable, Dict, List, Optional, Set, Tuple
from collections.abc import Iterable

from scriv.shell import CmdResult

# A function that simulates run_command.
CmdHandler = Callable[[List[str]], CmdResult]
CmdHandler = Callable[[list[str]], CmdResult]


class FakeRunCommand:
Expand All @@ -18,7 +19,7 @@ class FakeRunCommand:

def __init__(self, mocker):
"""Make the faker."""
self.handlers: Dict[str, CmdHandler] = {}
self.handlers: dict[str, CmdHandler] = {}
self.mocker = mocker
self.patch_module("scriv.shell")

Expand Down Expand Up @@ -50,19 +51,19 @@ class FakeGit:
def __init__(self, frc: FakeRunCommand) -> None:
"""Make a FakeGit from a FakeRunCommand."""
# Initialize with basic defaults.
self.config: Dict[str, str] = {
self.config: dict[str, str] = {
"core.bare": "false",
"core.repositoryformatversion": "0",
}
self.branch = "main"
self.editor = "vi"
self.tags: Set[str] = set()
self.remotes: Dict[str, Tuple[str, str]] = {}
self.tags: set[str] = set()
self.remotes: dict[str, tuple[str, str]] = {}

# Hook up our run_command handler.
frc.add_handler("git", self.run_command)

def run_command(self, argv: List[str]) -> CmdResult:
def run_command(self, argv: list[str]) -> CmdResult:
"""Simulate git commands."""
# todo: match/case someday
if argv[1] == "config":
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ def check_logs(caplog, expected):
Only caplog records from a logger mentioned in expected are considered.
"""
logger_names = set(r[0] for r in expected)
logger_names = {r[0] for r in expected}
records = [r for r in caplog.record_tuples if r[0] in logger_names]
assert records == expected
4 changes: 2 additions & 2 deletions tests/test_ghrel.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def scenario1(temp_dir, fake_git, mocker):
def mock_create_release(mocker):
"""Create a mock create_release that checks arguments."""

def _create_release(repo: str, release_data: Dict[str, Any]) -> None:
def _create_release(repo: str, release_data: dict[str, Any]) -> None:
assert repo
assert release_data["name"]
assert json.dumps(release_data)[0] == "{"
Expand All @@ -113,7 +113,7 @@ def mock_update_release(mocker):
"""Create a mock update_release that checks arguments."""

def _update_release(
release: Dict[str, Any], release_data: Dict[str, Any]
release: dict[str, Any], release_data: dict[str, Any]
) -> None:
assert release_data["name"]
assert release["url"]
Expand Down

0 comments on commit d1a7029

Please sign in to comment.