Verified Commit 7e06823e authored by Leonidas Spyropoulos's avatar Leonidas Spyropoulos
Browse files

refactor: remove redundand parenthesis when return tuple



Signed-off-by: Leonidas Spyropoulos's avatarLeonidas Spyropoulos <artafinde@archlinux.org>
parent d793193f
......@@ -127,7 +127,7 @@ class BasicAuthBackend(AuthenticationBackend):
user.nonce = util.make_nonce()
user.authenticated = True
return (AuthCredentials(["authenticated"]), user)
return AuthCredentials(["authenticated"]), user
def _auth_required(auth_goal: bool = True):
......
......@@ -52,7 +52,7 @@ def parse_dep(depstring):
depname = re.sub(r"(<|=|>).*", "", dep)
depcond = dep[len(depname) :]
return (depname, desc, depcond)
return depname, desc, depcond
def create_pkgbase(conn, pkgbase, user):
......
......@@ -239,12 +239,12 @@ def source_uri(pkgsrc: models.PackageSource) -> Tuple[str, str]:
the package base name.
:param pkgsrc: PackageSource instance
:return (text, uri) tuple
:return text, uri)tuple
"""
if "::" in pkgsrc.Source:
return pkgsrc.Source.split("::", 1)
elif "://" in pkgsrc.Source:
return (pkgsrc.Source, pkgsrc.Source)
return pkgsrc.Source, pkgsrc.Source
path = config.get("options", "source_file_uri")
pkgbasename = pkgsrc.Package.PackageBase.Name
return (pkgsrc.Source, path % (pkgsrc.Source, pkgbasename))
return pkgsrc.Source, path % (pkgsrc.Source, pkgbasename)
......@@ -160,9 +160,9 @@ def process_account_form(request: Request, user: models.User, args: dict[str, An
for check in checks:
check(**args, request=request, user=user, _=_)
except ValidationError as exc:
return (False, exc.data)
return False, exc.data
return (True, [])
return True, []
def make_account_form_context(
......
......@@ -213,7 +213,7 @@ async def package(
async def packages_unflag(request: Request, package_ids: list[int] = [], **kwargs):
if not package_ids:
return (False, ["You did not select any packages to unflag."])
return False, ["You did not select any packages to unflag."]
# Holds the set of package bases we're looking to unflag.
# Constructed below via looping through the packages query.
......@@ -226,14 +226,14 @@ async def packages_unflag(request: Request, package_ids: list[int] = [], **kwarg
creds.PKGBASE_UNFLAG, approved=[pkg.PackageBase.Flagger]
)
if not has_cred:
return (False, ["You did not select any packages to unflag."])
return False, ["You did not select any packages to unflag."]
if pkg.PackageBase not in bases:
bases.update({pkg.PackageBase})
for pkgbase in bases:
pkgbase_actions.pkgbase_unflag_instance(request, pkgbase)
return (True, ["The selected packages have been unflagged."])
return True, ["The selected packages have been unflagged."]
async def packages_notify(request: Request, package_ids: list[int] = [], **kwargs):
......@@ -271,13 +271,13 @@ async def packages_notify(request: Request, package_ids: list[int] = [], **kwarg
pkgbase_actions.pkgbase_notify_instance(request, pkgbase)
# TODO: This message does not yet have a translation.
return (True, ["The selected packages' notifications have been enabled."])
return True, ["The selected packages' notifications have been enabled."]
async def packages_unnotify(request: Request, package_ids: list[int] = [], **kwargs):
if not package_ids:
# TODO: This error does not yet have a translation.
return (False, ["You did not select any packages for notification removal."])
return False, ["You did not select any packages for notification removal."]
# TODO: This error does not yet have a translation.
error_tuple = (
......@@ -307,14 +307,14 @@ async def packages_unnotify(request: Request, package_ids: list[int] = [], **kwa
pkgbase_actions.pkgbase_unnotify_instance(request, pkgbase)
# TODO: This message does not yet have a translation.
return (True, ["The selected packages' notifications have been removed."])
return True, ["The selected packages' notifications have been removed."]
async def packages_adopt(
request: Request, package_ids: list[int] = [], confirm: bool = False, **kwargs
):
if not package_ids:
return (False, ["You did not select any packages to adopt."])
return False, ["You did not select any packages to adopt."]
if not confirm:
return (
......@@ -347,7 +347,7 @@ async def packages_adopt(
for pkgbase in bases:
pkgbase_actions.pkgbase_adopt_instance(request, pkgbase)
return (True, ["The selected packages have been adopted."])
return True, ["The selected packages have been adopted."]
def disown_all(request: Request, pkgbases: list[models.PackageBase]) -> list[str]:
......@@ -364,7 +364,7 @@ async def packages_disown(
request: Request, package_ids: list[int] = [], confirm: bool = False, **kwargs
):
if not package_ids:
return (False, ["You did not select any packages to disown."])
return False, ["You did not select any packages to disown."]
if not confirm:
return (
......@@ -397,9 +397,9 @@ async def packages_disown(
# Now, disown all the bases if we can.
if errors := disown_all(request, bases):
return (False, errors)
return False, errors
return (True, ["The selected packages have been disowned."])
return True, ["The selected packages have been disowned."]
async def packages_delete(
......@@ -410,7 +410,7 @@ async def packages_delete(
**kwargs,
):
if not package_ids:
return (False, ["You did not select any packages to delete."])
return False, ["You did not select any packages to delete."]
if not confirm:
return (
......@@ -422,7 +422,7 @@ async def packages_delete(
)
if not request.user.has_credential(creds.PKGBASE_DELETE):
return (False, ["You do not have permission to delete packages."])
return False, ["You do not have permission to delete packages."]
# set-ify package_ids and query the database for related records.
package_ids = set(package_ids)
......@@ -432,7 +432,7 @@ async def packages_delete(
# Let the user know there was an issue with their input: they have
# provided at least one package_id which does not exist in the DB.
# TODO: This error has not yet been translated.
return (False, ["One of the packages you selected does not exist."])
return False, ["One of the packages you selected does not exist."]
# Make a set out of all package bases related to `packages`.
bases = {pkg.PackageBase for pkg in packages}
......@@ -448,7 +448,7 @@ async def packages_delete(
)
util.apply_all(notifs, lambda n: n.send())
return (True, ["The selected packages have been deleted."])
return True, ["The selected packages have been deleted."]
# A mapping of action string -> callback functions used within the
......
......@@ -46,7 +46,7 @@ class FlysprayLinksInlineProcessor(markdown.inlinepatterns.InlineProcessor):
el = Element("a")
el.set("href", f"https://bugs.archlinux.org/task/{m.group(1)}")
el.text = markdown.util.AtomicString(m.group(0))
return (el, m.start(0), m.end(0))
return el, m.start(0), m.end(0)
class FlysprayLinksExtension(markdown.extensions.Extension):
......@@ -74,7 +74,7 @@ class GitCommitsInlineProcessor(markdown.inlinepatterns.InlineProcessor):
oid = m.group(1)
if oid not in self._repo:
# Unknown OID; preserve the orginal text.
return (None, None, None)
return None, None, None
el = Element("a")
commit_uri = aurweb.config.get("options", "commit_uri")
......@@ -83,7 +83,7 @@ class GitCommitsInlineProcessor(markdown.inlinepatterns.InlineProcessor):
"href", commit_uri % (quote_plus(self._head), quote_plus(oid[:prefixlen]))
)
el.text = markdown.util.AtomicString(oid[:prefixlen])
return (el, m.start(0), m.end(0))
return el, m.start(0), m.end(0)
class GitCommitsExtension(markdown.extensions.Extension):
......
......@@ -107,7 +107,7 @@ def sanitize_params(offset: str, per_page: str) -> Tuple[int, int]:
except ValueError:
per_page = defaults.PP
return (offset, per_page)
return offset, per_page
def strtobool(value: Union[str, bool]) -> bool:
......@@ -187,7 +187,7 @@ def parse_ssh_key(string: str) -> Tuple[str, str]:
if proc.returncode:
raise invalid_exc
return (prefix, key)
return prefix, key
def parse_ssh_keys(string: str) -> list[Tuple[str, str]]:
......@@ -199,4 +199,4 @@ def shell_exec(cmdline: str, cwd: str) -> Tuple[int, str, str]:
args = shlex.split(cmdline)
proc = Popen(args, cwd=cwd, stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
return (proc.returncode, out.decode().strip(), err.decode().strip())
return proc.returncode, out.decode().strip(), err.decode().strip()
......@@ -1149,7 +1149,7 @@ def test_packages_post_unknown_action(client: TestClient, user: User, package: P
def test_packages_post_error(client: TestClient, user: User, package: Package):
async def stub_action(request: Request, **kwargs):
return (False, ["Some error."])
return False, ["Some error."]
actions = {"stub": stub_action}
with mock.patch.dict("aurweb.routers.packages.PACKAGE_ACTIONS", actions):
......@@ -1170,7 +1170,7 @@ def test_packages_post_error(client: TestClient, user: User, package: Package):
def test_packages_post(client: TestClient, user: User, package: Package):
async def stub_action(request: Request, **kwargs):
return (True, ["Some success."])
return True, ["Some success."]
actions = {"stub": stub_action}
with mock.patch.dict("aurweb.routers.packages.PACKAGE_ACTIONS", actions):
......
......@@ -1315,7 +1315,7 @@ def test_packages_post_unknown_action(client: TestClient, user: User, package: P
def test_packages_post_error(client: TestClient, user: User, package: Package):
async def stub_action(request: Request, **kwargs):
return (False, ["Some error."])
return False, ["Some error."]
actions = {"stub": stub_action}
with mock.patch.dict("aurweb.routers.packages.PACKAGE_ACTIONS", actions):
......@@ -1336,7 +1336,7 @@ def test_packages_post_error(client: TestClient, user: User, package: Package):
def test_packages_post(client: TestClient, user: User, package: Package):
async def stub_action(request: Request, **kwargs):
return (True, ["Some success."])
return True, ["Some success."]
actions = {"stub": stub_action}
with mock.patch.dict("aurweb.routers.packages.PACKAGE_ACTIONS", actions):
......
......@@ -24,7 +24,7 @@ class FakeProcess:
"""We need this constructor to remain compatible with Popen."""
def communicate(self) -> Tuple[bytes, bytes]:
return (self.stdout, self.stderr)
return self.stdout, self.stderr
def terminate(self) -> None:
raise Exception("Fake termination.")
......
......@@ -42,7 +42,7 @@ def email_pieces(voteinfo: TUVoteInfo) -> Tuple[str, str]:
f"[1]. The voting period\nends in less than 48 hours.\n\n"
f"[1] {aur_location}/tu/?id={voteinfo.ID}"
)
return (subject, content)
return subject, content
@pytest.fixture
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment