Skip to content

Commit

Permalink
Upgrade some old syntax (#4338)
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Kłoczko <kloczek@github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
  • Loading branch information
kloczek and JelleZijlstra committed Apr 27, 2024
1 parent 455de77 commit 0c033f3
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 23 deletions.
3 changes: 1 addition & 2 deletions docs/conf.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
Expand All @@ -24,7 +23,7 @@
def make_pypi_svg(version: str) -> None:
template: Path = CURRENT_DIR / "_static" / "pypi_template.svg"
target: Path = CURRENT_DIR / "_static" / "pypi.svg"
with open(str(template), "r", encoding="utf8") as f:
with open(str(template), encoding="utf8") as f:
svg: str = string.Template(f.read()).substitute(version=version)
with open(str(target), "w", encoding="utf8") as f:
f.write(svg)
Expand Down
7 changes: 1 addition & 6 deletions scripts/diff_shades_gha_helper.py
Expand Up @@ -24,17 +24,12 @@
from base64 import b64encode
from io import BytesIO
from pathlib import Path
from typing import Any
from typing import Any, Final, Literal

import click
import urllib3
from packaging.version import Version

if sys.version_info >= (3, 8):
from typing import Final, Literal
else:
from typing_extensions import Final, Literal

COMMENT_FILE: Final = ".pr-comment.json"
DIFF_STEP_NAME: Final = "Generate HTML diff report"
DOCS_URL: Final = (
Expand Down
12 changes: 6 additions & 6 deletions scripts/migrate-black.py
Expand Up @@ -9,7 +9,7 @@


def git(*args: str) -> str:
return check_output(["git"] + list(args)).decode("utf8").strip()
return check_output(["git", *args]).decode("utf8").strip()


def blackify(base_branch: str, black_command: str, logger: logging.Logger) -> int:
Expand All @@ -26,19 +26,19 @@ def blackify(base_branch: str, black_command: str, logger: logging.Logger) -> in
merge_base = git("merge-base", "HEAD", base_branch)
if not merge_base:
logger.error(
"Could not find a common commit for current head and %s" % base_branch
f"Could not find a common commit for current head and {base_branch}"
)
return 1

commits = git(
"log", "--reverse", "--pretty=format:%H", "%s~1..HEAD" % merge_base
"log", "--reverse", "--pretty=format:%H", f"{merge_base}~1..HEAD"
).split()
for commit in commits:
git("checkout", commit, "-b%s-black" % commit)
git("checkout", commit, f"-b{commit}-black")
check_output(black_command, shell=True)
git("commit", "-aqm", "blackify")

git("checkout", base_branch, "-b%s-black" % current_branch)
git("checkout", base_branch, f"-b{current_branch}-black")

for last_commit, commit in zip(commits, commits[1:]):
allow_empty = (
Expand All @@ -51,7 +51,7 @@ def blackify(base_branch: str, black_command: str, logger: logging.Logger) -> in
"diff",
"--binary",
"--find-copies",
"%s-black..%s-black" % (last_commit, commit),
f"{last_commit}-black..{commit}-black"
],
stdout=PIPE,
)
Expand Down
7 changes: 3 additions & 4 deletions scripts/release.py
Expand Up @@ -11,8 +11,7 @@
import sys
from datetime import datetime
from pathlib import Path
from subprocess import PIPE, run
from typing import List
from subprocess import run

LOG = logging.getLogger(__name__)
NEW_VERSION_CHANGELOG_TEMPLATE = """\
Expand Down Expand Up @@ -70,9 +69,9 @@ class NoGitTagsError(Exception): ... # noqa: E701,E761

# TODO: Do better with alpha + beta releases
# Maybe we vendor packaging library
def get_git_tags(versions_only: bool = True) -> List[str]:
def get_git_tags(versions_only: bool = True) -> list[str]:
"""Pull out all tags or calvers only"""
cp = run(["git", "tag"], stdout=PIPE, stderr=PIPE, check=True, encoding="utf8")
cp = run(["git", "tag"], capture_output=True, check=True, encoding="utf8")
if not cp.stdout:
LOG.error(f"Returned no git tags stdout: {cp.stderr}")
raise NoGitTagsError
Expand Down
4 changes: 2 additions & 2 deletions tests/optional.py
Expand Up @@ -119,13 +119,13 @@ def pytest_collection_modifyitems(config: "Config", items: "List[Node]") -> None
item.add_marker(skip_mark(frozenset(optional_markers_on_test)))


@lru_cache()
@lru_cache
def skip_mark(tests: FrozenSet[str]) -> "MarkDecorator":
names = ", ".join(sorted(tests))
return pytest.mark.skip(reason=f"Marked with disabled optional tests ({names})")


@lru_cache()
@lru_cache
def no(name: str) -> str:
if name.startswith("no_"):
return name[len("no_") :]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_black.py
Expand Up @@ -2984,7 +2984,7 @@ def test_equivalency_ast_parse_failure_includes_error(self) -> None:


try:
with open(black.__file__, "r", encoding="utf-8") as _bf:
with open(black.__file__, encoding="utf-8") as _bf:
black_source_lines = _bf.readlines()
except UnicodeDecodeError:
if not black.COMPILED:
Expand Down
4 changes: 2 additions & 2 deletions tests/util.py
Expand Up @@ -230,7 +230,7 @@ def _parse_minimum_version(version: str) -> Tuple[int, int]:
return int(major), int(minor)


@functools.lru_cache()
@functools.lru_cache
def get_flags_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser()
parser.add_argument(
Expand Down Expand Up @@ -303,7 +303,7 @@ def parse_mode(flags_line: str) -> TestCaseArgs:


def read_data_from_file(file_name: Path) -> Tuple[TestCaseArgs, str, str]:
with open(file_name, "r", encoding="utf8") as test:
with open(file_name, encoding="utf8") as test:
lines = test.readlines()
_input: List[str] = []
_output: List[str] = []
Expand Down

0 comments on commit 0c033f3

Please sign in to comment.