← Back to team overview

sts-sponsors team mailing list archive

[Merge] ~ack/maas/+git/maas-release-tools:pyupgrade-310 into ~maas-committers/maas/+git/maas-release-tools:main

 

Alberto Donato has proposed merging ~ack/maas/+git/maas-release-tools:pyupgrade-310 into ~maas-committers/maas/+git/maas-release-tools:main.

Commit message:
run pyupgrade to Python 3.10



Requested reviews:
  MAAS Committers (maas-committers)

For more details, see:
https://code.launchpad.net/~ack/maas/+git/maas-release-tools/+merge/439053
-- 
Your team MAAS Committers is requested to review the proposed merge of ~ack/maas/+git/maas-release-tools:pyupgrade-310 into ~maas-committers/maas/+git/maas-release-tools:main.
diff --git a/maas_release_tools/git.py b/maas_release_tools/git.py
index 6e90a1c..eeb4250 100644
--- a/maas_release_tools/git.py
+++ b/maas_release_tools/git.py
@@ -2,7 +2,7 @@
 
 import re
 import subprocess
-from typing import Dict, List, NamedTuple, Optional
+from typing import NamedTuple
 from urllib.parse import ParseResult, urlparse
 
 _REMOTE_URL_RE = re.compile(r"(?P<name>.+)\t(?P<url>.+) \((?P<type>.+)\)$")
@@ -21,7 +21,7 @@ class GitCommandResult(NamedTuple):
 class Git:
     """A wrapper around the git CLI."""
 
-    def __init__(self, cwd: Optional[str] = None) -> None:
+    def __init__(self, cwd: str | None = None) -> None:
         self.cwd = cwd
 
     def get_short_rev(self, ref: str) -> str:
@@ -34,14 +34,14 @@ class Git:
         result = self._run("rev-list", "-n", "1", f"tags/{tag}")
         return result.output
 
-    def get_remote_branches_containing(self, ref: str) -> List[List[str]]:
+    def get_remote_branches_containing(self, ref: str) -> list[list[str]]:
         result = self._run("branch", "-r", "--contains", ref)
         return [
             branch.strip().split("/", 1)
             for branch in result.output.splitlines()
         ]
 
-    def get_remote_urls(self) -> Dict[str, ParseResult]:
+    def get_remote_urls(self) -> dict[str, ParseResult]:
         """Return a dict mapping remote names to their fetch URLs."""
         result = self._run("remote", "-v")
         urls = {}
@@ -55,7 +55,7 @@ class Git:
             urls[entry["name"]] = urlparse(entry["url"])
         return urls
 
-    def get_official_remote(self, remote_path: str = "/maas") -> Optional[str]:
+    def get_official_remote(self, remote_path: str = "/maas") -> str | None:
         for name, url in self.get_remote_urls().items():
             if url.path == remote_path:
                 return name
@@ -95,8 +95,7 @@ class Git:
     def _run(self, *args) -> GitCommandResult:
         proc = subprocess.run(
             ["git", *args],
-            stdout=subprocess.PIPE,
-            stderr=subprocess.PIPE,
+            capture_output=True,
             text=True,
             cwd=self.cwd,
         )
diff --git a/maas_release_tools/launchpad.py b/maas_release_tools/launchpad.py
index cea786e..2d1479e 100644
--- a/maas_release_tools/launchpad.py
+++ b/maas_release_tools/launchpad.py
@@ -1,11 +1,11 @@
 """Interact with Launchpad API."""
 
+from collections.abc import Sequence
 from contextlib import contextmanager
 from datetime import datetime, timezone
 from functools import cached_property
 import logging
 from pathlib import Path
-from typing import List, Optional, Sequence
 
 from launchpadlib.launchpad import Launchpad
 from lazr.restfulclient.errors import NotFound
@@ -30,7 +30,7 @@ class LaunchpadActions:
     def __init__(
         self,
         project: str,
-        credentials_file: Optional[Path] = None,
+        credentials_file: Path | None = None,
         dry_run: bool = False,
     ):
         self.lp = self._get_client(credentials_file=credentials_file)
@@ -87,7 +87,7 @@ class LaunchpadActions:
         self,
         origin_milestone: str,
         dest_milestone: str,
-        fixed_before: Optional[str] = None,
+        fixed_before: str | None = None,
     ):
         """Move bugs that are done from a milestone to another."""
         origin = self.get_milestone(origin_milestone)
@@ -114,7 +114,7 @@ class LaunchpadActions:
             )
 
     def assign_bugs_to_milestone(
-        self, bugs: List[str], milestone_name: str
+        self, bugs: list[str], milestone_name: str
     ) -> None:
         """Assign bugs to a milestone, re-opening and closing as necessary."""
         with self._active_milestone(milestone_name) as milestone:
@@ -158,9 +158,7 @@ class LaunchpadActions:
         else:
             self.logger.info(f"milestone {milestone.name} already released")
 
-    def _get_client(
-        self, credentials_file: Optional[Path] = None
-    ) -> Launchpad:
+    def _get_client(self, credentials_file: Path | None = None) -> Launchpad:
         """Return a Launchpad API client."""
         kwargs = {
             "service_root": "https://api.launchpad.net";,
@@ -200,7 +198,7 @@ class LaunchpadActions:
         orig_milestone,
         dest_milestone,
         dry_run: bool = False,
-        fixed_before: Optional[datetime] = None,
+        fixed_before: datetime | None = None,
     ):
         bug_tasks = orig_milestone.searchTasks(status=statuses)
         for bug_task in bug_tasks:
diff --git a/maas_release_tools/maasci.py b/maas_release_tools/maasci.py
index 980f6b4..926555a 100644
--- a/maas_release_tools/maasci.py
+++ b/maas_release_tools/maasci.py
@@ -4,7 +4,6 @@ from functools import cached_property
 import logging
 from pathlib import Path
 import re
-from typing import Optional, Tuple
 
 from jenkins import Jenkins, JenkinsException
 
@@ -22,8 +21,8 @@ class JenkinsConnectionFailed(Exception):
 class JenkinsActions:
     def __init__(
         self,
-        server_section: Optional[str] = None,
-        jenkins_config: Optional[Path] = None,
+        server_section: str | None = None,
+        jenkins_config: Path | None = None,
         dry_run: bool = False,
     ):
         self._jenkins = self._get_client(
@@ -34,8 +33,8 @@ class JenkinsActions:
 
     def _get_client(
         self,
-        server_section: Optional[str] = None,
-        jenkins_config: Optional[Path] = None,
+        server_section: str | None = None,
+        jenkins_config: Path | None = None,
     ) -> Jenkins:
         """Return a Jenkins API client."""
         jenkins_config = jenkins_config or JJB_CONFIG
@@ -55,7 +54,7 @@ class JenkinsActions:
 
     def get_last_build_result_for_rev(
         self, job_name: str, rev: str
-    ) -> Tuple[str, str]:
+    ) -> tuple[str, str]:
         try:
             job = self._jenkins.get_job_info(job_name)
             for build in job["builds"]:
diff --git a/maas_release_tools/makefile.py b/maas_release_tools/makefile.py
index 1b15b73..abe23f8 100644
--- a/maas_release_tools/makefile.py
+++ b/maas_release_tools/makefile.py
@@ -37,8 +37,7 @@ class Makefile:
     def _run(self, *args) -> MakeResult:
         proc = subprocess.run(
             ["make", *args],
-            stdout=subprocess.PIPE,
-            stderr=subprocess.PIPE,
+            capture_output=True,
             text=True,
             cwd=self.cwd,
         )
diff --git a/maas_release_tools/scripts/__main__.py b/maas_release_tools/scripts/__main__.py
index 5a71b5d..cf25ce9 100644
--- a/maas_release_tools/scripts/__main__.py
+++ b/maas_release_tools/scripts/__main__.py
@@ -1,9 +1,7 @@
-from typing import List
-
 from pkg_resources import get_distribution
 
 
-def get_all_script_names() -> List[str]:
+def get_all_script_names() -> list[str]:
     """Return names of all scripts for the package."""
     dist = get_distribution("maas-release-tools")
     return sorted(dist.get_entry_map("console_scripts"))
diff --git a/maas_release_tools/scripts/release_status.py b/maas_release_tools/scripts/release_status.py
index 6db3367..aba0dc5 100644
--- a/maas_release_tools/scripts/release_status.py
+++ b/maas_release_tools/scripts/release_status.py
@@ -15,13 +15,13 @@ will go smoother.
 from abc import ABC, abstractmethod
 from argparse import ArgumentParser, FileType
 import base64
+from collections.abc import Iterable
 from datetime import date, timedelta
 from functools import lru_cache
 import glob
 import json
 import os
 import sys
-from typing import Iterable
 
 from debian.changelog import Changelog
 from lazr.restfulclient.errors import NotFound
@@ -91,7 +91,7 @@ def get_macaroon_auth_error(res, snap_name):
 @lru_cache(maxsize=1)
 def get_ubuntu_series() -> str:
     try:
-        with open("debian/changelog", "r") as fh:
+        with open("debian/changelog") as fh:
             ch = Changelog(fh, max_blocks=1)
             return str(ch.distributions)
     except OSError:
@@ -313,7 +313,7 @@ class MAASVersion(ReleaseStep):
             error_message = f"setup.cfg has {setup_version} (expected {self.preparer.version.python_version})"
             return False, error_message
         deb_ver = self.preparer.version.deb_version
-        with open("debian/changelog", "r") as fh:
+        with open("debian/changelog") as fh:
             ch = Changelog(fh, max_blocks=1)
             if ch.upstream_version != deb_ver:
                 return (
@@ -487,7 +487,7 @@ class MAASPPA(ReleaseStep):
                     f"Missing PPA dependencies: {', '.join(missing_deps)}"
                 )
 
-        ppa_archs = set(processor.name for processor in self.ppa.processors)
+        ppa_archs = {processor.name for processor in self.ppa.processors}
         missing_archs = sorted(set(BUILD_ARCHS).difference(ppa_archs))
         if missing_archs:
             return False, (
@@ -1342,7 +1342,7 @@ def parse_args():
 def main():
     args = parse_args()
     try:
-        with open("release.macaroon", "r") as credentials_file:
+        with open("release.macaroon") as credentials_file:
             raw = base64.b64decode(credentials_file.read())
         macaroons = json.loads(raw)["v"]
     except (OSError, json.decoder.JSONDecodeError):
diff --git a/maas_release_tools/scripts/release_upload.py b/maas_release_tools/scripts/release_upload.py
index 0bcf1c2..2973eb1 100644
--- a/maas_release_tools/scripts/release_upload.py
+++ b/maas_release_tools/scripts/release_upload.py
@@ -5,7 +5,7 @@ from pathlib import Path
 import re
 from subprocess import CalledProcessError, check_output, PIPE
 import sys
-from typing import cast, Optional
+from typing import cast
 
 from packaging.version import Version
 
@@ -15,7 +15,7 @@ class PPAURL:
 
     url: str
     release: Version
-    pocket: Optional[str]
+    pocket: str | None
 
     _PPA_RE = re.compile(r"^ppa:maas/(?P<release>[0-9.]+)(-(?P<pocket>.*))?$")
 
diff --git a/maas_release_tools/version.py b/maas_release_tools/version.py
index fe43bd7..03ab82d 100644
--- a/maas_release_tools/version.py
+++ b/maas_release_tools/version.py
@@ -1,9 +1,9 @@
 """Utilities to deal with versions."""
 
+from collections.abc import Iterable
 from configparser import ConfigParser
 from dataclasses import dataclass
 from pathlib import Path
-from typing import Iterable
 
 from packaging.version import Version
 

Follow ups