Skip to content

Commit

Permalink
Strict nullability for rest of lib.user
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasjuhrich committed Sep 20, 2024
1 parent 8c72119 commit cd4b437
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pycroft/helpers/printing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def generate_user_sheet(
new_user: bool,
wifi: bool,
bank_account: BankAccount,
user: User | None = None,
user: User = None,
user_id: str | None = None,
plain_user_password: str | None = None,
generation_purpose: str = "",
Expand Down
12 changes: 6 additions & 6 deletions pycroft/lib/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

from pycroft.lib.exc import PycroftLibException

mail_envelope_from = os.environ.get('PYCROFT_MAIL_ENVELOPE_FROM')
mail_from = os.environ.get('PYCROFT_MAIL_FROM')
mail_reply_to = os.environ.get('PYCROFT_MAIL_REPLY_TO')
smtp_host = os.environ.get('PYCROFT_SMTP_HOST')
mail_envelope_from = os.environ["PYCROFT_MAIL_ENVELOPE_FROM"]
mail_from = os.environ["PYCROFT_MAIL_FROM"]
mail_reply_to = os.environ["PYCROFT_MAIL_REPLY_TO"]
smtp_host = os.environ["PYCROFT_SMTP_HOST"]
smtp_port = int(os.environ.get('PYCROFT_SMTP_PORT', 465))
smtp_user = os.environ.get('PYCROFT_SMTP_USER')
smtp_password = os.environ.get('PYCROFT_SMTP_PASSWORD')
smtp_user = os.environ["PYCROFT_SMTP_USER"]
smtp_password = os.environ["PYCROFT_SMTP_PASSWORD"]
smtp_ssl = os.environ.get('PYCROFT_SMTP_SSL', 'ssl')
template_path_type = os.environ.get('PYCROFT_TEMPLATE_PATH_TYPE', 'filesystem')
template_path = os.environ.get('PYCROFT_TEMPLATE_PATH', 'pycroft/templates')
Expand Down
2 changes: 1 addition & 1 deletion pycroft/lib/user/blocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def block(
user: User,
reason: str,
processor: User,
during: Interval[DateTimeTz] = None,
during: Interval[DateTimeTz] | None = None,
violation: bool = True,
) -> User:
"""Suspend a user during a given interval.
Expand Down
2 changes: 1 addition & 1 deletion pycroft/lib/user/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def edit_email(


@with_transaction
def edit_birthdate(user: User, birthdate: date, processor: User) -> User:
def edit_birthdate(user: User, birthdate: date | None, processor: User) -> User:
"""
Changes the birthdate of a user and creates a log entry.
Expand Down
8 changes: 5 additions & 3 deletions pycroft/lib/user/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def format_user_mail(user: User, text: str) -> str:
id=encode_type2_user_id(user.id),
email=user.email if user.email else "-",
email_internal=user.email_internal,
room_short=user.room.short_name if user.room_id is not None else "-",
room_short=user.room.short_name if user.room is not None else "-",
swdd_person_id=user.swdd_person_id if user.swdd_person_id else "-",
)

Expand All @@ -48,8 +48,8 @@ def user_send_mails(
template: MailTemplate | None = None,
soft_fail: bool = False,
use_internal: bool = True,
body_plain: str = None,
subject: str = None,
body_plain: str | None = None,
subject: str | None = None,
**kwargs: t.Any,
) -> None:
"""
Expand Down Expand Up @@ -94,6 +94,8 @@ def user_send_mails(
# No template given, use formatted body_mail instead.
if not isinstance(user, User):
raise ValueError("Plaintext email not supported for other User types.")
if body_plain is None:
raise ValueError("Must use either template or body_plain")

html = None
plaintext = format_user_mail(user, body_plain)
Expand Down
6 changes: 3 additions & 3 deletions pycroft/lib/user/user_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
def store_user_sheet(
new_user: bool,
wifi: bool,
user: User | None = None,
user: User,
timeout: int = 15,
plain_user_password: str = None,
plain_user_password: str | None = None,
generation_purpose: str = "",
plain_wifi_password: str = "",
) -> WebStorage:
Expand Down Expand Up @@ -65,7 +65,7 @@ def get_user_sheet(sheet_id: int) -> bytes | None:
def generate_user_sheet(
new_user: bool,
wifi: bool,
user: User | None = None,
user: User,
plain_user_password: str | None = None,
generation_purpose: str = "",
plain_wifi_password: str = "",
Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ module = [
"ldap_sync.*",
"pycroft.lib",
"pycroft.lib.*",
"pycroft.lib.user.*",
"pycroft.external_services",
"pycroft.external_services.*",
"pycroft.helpers",
Expand All @@ -172,9 +171,9 @@ disallow_untyped_globals = true
module = [
"pycroft.model.task_serialization",
"pycroft.lib.finance",
"pycroft.lib.user.lifecycle",
"pycroft.lib.user.mail_confirmation",
"pycroft.lib.user.member_request",
"pycroft.lib.mail",
"pycroft.lib.user",
"pycroft.lib.user.*",
]
strict_optional = true

Expand Down

0 comments on commit cd4b437

Please sign in to comment.