Skip to content

Commit

Permalink
quality/user.py: simplify type hint syntax using new '|' syntax inste…
Browse files Browse the repository at this point in the history
…ad of Optional/Union
  • Loading branch information
alexAubin committed Feb 7, 2025
1 parent b88c3b7 commit c3ef86f
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions src/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import re
import subprocess
from logging import getLogger
from typing import TYPE_CHECKING, Any, Callable, Optional, TextIO, Union, cast
from typing import TYPE_CHECKING, Any, Callable, TextIO, Union, cast

from moulinette import Moulinette, m18n
from moulinette.utils.process import check_output
Expand Down Expand Up @@ -62,7 +62,7 @@
ADMIN_ALIASES = ["root", "admin", "admins", "webmaster", "postmaster", "abuse"]


def user_list(fields: Optional[list[str]] = None) -> dict[str, dict[str, Any]]:
def user_list(fields: list[str] | None = None) -> dict[str, dict[str, Any]]:
from yunohost.utils.ldap import _get_ldap_interface

ldap_attrs = {
Expand Down Expand Up @@ -394,16 +394,16 @@ def user_delete(
def user_update(
operation_logger: "OperationLogger",
username: str,
mail: Optional[str] = None,
change_password: Optional[str] = None,
mail: str | None = None,
change_password: str | None = None,
add_mailforward: None | str | list[str] = None,
remove_mailforward: None | str | list[str] = None,
add_mailalias: None | str | list[str] = None,
remove_mailalias: None | str | list[str] = None,
mailbox_quota: Optional[str] = None,
mailbox_quota: str | None = None,
from_import: bool = False,
fullname: Optional[str] = None,
loginShell: Optional[str] = None,
fullname: str | None = None,
loginShell: str | None = None,
):
if fullname and fullname.strip():
fullname = fullname.strip()
Expand Down Expand Up @@ -688,10 +688,6 @@ def user_info(username: str) -> dict[str, str]:
def user_export() -> Union[str, "HTTPResponseType"]:
"""
Export users into CSV
Keyword argument:
csv -- CSV file with columns username;firstname;lastname;password;mailbox-quota;mail;mail-alias;mail-forward;groups
"""
import csv # CSV are needed only in this function
from io import StringIO
Expand Down Expand Up @@ -1063,7 +1059,7 @@ def user_group_list(
def user_group_create(
operation_logger: "OperationLogger",
groupname: str,
gid: Optional[str] = None,
gid: str | None = None,
primary_group: bool = False,
sync_perm: bool = True,
) -> dict[str, str]:
Expand Down Expand Up @@ -1442,7 +1438,7 @@ def user_group_info(groupname: str) -> dict[str, Any]:

def user_group_add(
groupname: str, usernames: list[str], force: bool = False, sync_perm: bool = True
) -> Optional[dict[str, Any]]:
) -> dict[str, Any] | None:
"""
Add user(s) to a group
Expand All @@ -1456,7 +1452,7 @@ def user_group_add(

def user_group_remove(
groupname: str, usernames: list[str], force: bool = False, sync_perm: bool = True
) -> Optional[dict[str, Any]]:
) -> dict[str, Any] | None:
"""
Remove user(s) from a group
Expand All @@ -1472,15 +1468,15 @@ def user_group_remove(

def user_group_add_mailalias(
groupname: str, aliases: list[str], force: bool = False
) -> Optional[dict[str, Any]]:
) -> dict[str, Any] | None:
return user_group_update(
groupname, add_mailalias=aliases, force=force, sync_perm=False
)


def user_group_remove_mailalias(
groupname: str, aliases: list[str], force: bool = False
) -> Optional[dict[str, Any]]:
) -> dict[str, Any] | None:
return user_group_update(
groupname, remove_mailalias=aliases, force=force, sync_perm=False
)
Expand Down Expand Up @@ -1516,7 +1512,7 @@ def user_permission_update(
def user_permission_add(
permission: str,
names: list[str],
protected: Optional[bool] = None,
protected: bool | None = None,
force: bool = False,
sync_perm: bool = True,
):
Expand All @@ -1531,7 +1527,7 @@ def user_permission_add(
def user_permission_remove(
permission: str,
names: list[str],
protected: Optional[bool] = None,
protected: bool | None = None,
force: bool = False,
sync_perm: bool = True,
):
Expand Down Expand Up @@ -1566,7 +1562,7 @@ def user_ssh_list_keys(username: str) -> dict[str, dict[str, str]]:
return yunohost.ssh.user_ssh_list_keys(username)


def user_ssh_add_key(username: str, key: str, comment: Optional[str] = None) -> None:
def user_ssh_add_key(username: str, key: str, comment: str | None = None) -> None:
return yunohost.ssh.user_ssh_add_key(username, key, comment)


Expand Down

0 comments on commit c3ef86f

Please sign in to comment.