From 069a6926c0bc6788de402e8fd0787dbbf99d87a3 Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Tue, 31 Jan 2023 17:28:33 +0100 Subject: [PATCH] Implement conventions found by pylint Signed-off-by: Benjamin Drung --- requestsync | 5 +++-- syncpackage | 6 +++--- ubuntutools/question.py | 2 +- ubuntutools/sponsor_patch/sponsor_patch.py | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/requestsync b/requestsync index 1121d92..a65ea89 100755 --- a/requestsync +++ b/requestsync @@ -150,7 +150,7 @@ def main(): ) if not args.lpapi and not mailserver_host: try: - import DNS + import DNS # pylint: disable=import-outside-toplevel DNS.DiscoverNameServers() mxlist = DNS.mxlookup(bug_mail_domain) @@ -167,6 +167,7 @@ def main(): mailserver_pass = config.get_value("SMTP_PASS", compat_keys=["UBUSMTP_PASS", "DEBSMTP_PASS"]) # import the needed requestsync module + # pylint: disable=import-outside-toplevel if args.lpapi: from ubuntutools.lp.lpapicache import Distribution, Launchpad from ubuntutools.requestsync.lp import ( @@ -259,7 +260,7 @@ def main(): # Stop if Ubuntu has already the version from Debian or a newer version if (ubuntu_version >= debian_version) and args.lpapi: # try rmadison - import ubuntutools.requestsync.mail + import ubuntutools.requestsync.mail # pylint: disable=import-outside-toplevel try: debian_srcpkg = ubuntutools.requestsync.mail.get_debian_srcpkg(srcpkg, distro) diff --git a/syncpackage b/syncpackage index abee79a..b1903e6 100755 --- a/syncpackage +++ b/syncpackage @@ -82,8 +82,8 @@ def add_fixed_bugs(changes, bugs): # Remove duplicates bugs = set(str(bug) for bug in bugs) - for i in range(len(changes)): - if changes[i].startswith("Launchpad-Bugs-Fixed:"): + for i, change in enumerate(changes): + if change.startswith("Launchpad-Bugs-Fixed:"): bugs.update(changes[i][22:].strip().split(" ")) changes[i] = "Launchpad-Bugs-Fixed: %s" % (" ".join(bugs)) break @@ -285,7 +285,7 @@ def fetch_source_pkg(package, dist, version, component, ubuntu_release, mirror): dist = "unstable" requested_version = version - if type(version) == str: + if isinstance(version, str): version = Version(version) if version is None or component is None: diff --git a/ubuntutools/question.py b/ubuntutools/question.py index 35d5460..f433e0e 100644 --- a/ubuntutools/question.py +++ b/ubuntutools/question.py @@ -97,7 +97,7 @@ def input_number(question, min_number, max_number, default=None): print("Please input a number between %i and %i." % (min_number, max_number)) except ValueError: print("Please input a number.") - assert type(selected) == int + assert isinstance(selected, int) return selected diff --git a/ubuntutools/sponsor_patch/sponsor_patch.py b/ubuntutools/sponsor_patch/sponsor_patch.py index 479b707..68f94df 100644 --- a/ubuntutools/sponsor_patch/sponsor_patch.py +++ b/ubuntutools/sponsor_patch/sponsor_patch.py @@ -245,8 +245,8 @@ def get_open_ubuntu_bug_task(launchpad, bug, branch=None): Logger.info( "https://launchpad.net/bugs/%i has %i Ubuntu tasks:", bug_id, len(ubuntu_tasks) ) - for i in range(len(ubuntu_tasks)): - print("%i) %s" % (i + 1, ubuntu_tasks[i].get_package_and_series())) + for i, ubuntu_task in enumerate(ubuntu_tasks): + print("%i) %s" % (i + 1, ubuntu_task.get_package_and_series())) selected = input_number( "To which Ubuntu task does the patch belong", 1, len(ubuntu_tasks) )