Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade pipeline to mypy v1.8 #687

Merged
merged 5 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@
}
# see https://github.com/sphinx-doc/sphinx/issues/10480#issuecomment-1221396022
import sphinx.ext.autodoc
sphinx.ext.autodoc.NewTypeDataDocumenter.directivetype = 'class'

try:
sphinx.ext.autodoc.NewTypeDataDocumenter.directivetype = "class"
except AttributeError:
pass

todo_include_todos = True
# -- Options for HTML output ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion ldap_sync/concepts/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _canonicalize_to_list(
if isinstance(value, list):
return list(value)
if value == "" or value == b"" or value is None:
return [] # type: ignore
return []
# str, byte, int – or unknown. But good fallback.
return [value] # type: ignore

Expand Down
6 changes: 2 additions & 4 deletions pycroft/lib/finance/membership_fee.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,12 @@ def post_transactions_for_membership_fee(
).fetchall()

if not simulate:
# `over` not typed yet,
# see https://github.com/sqlalchemy/sqlalchemy/issues/6810
numbered_users = (
select(
users.c.id,
users.c.fee_account_id.label("fee_account_id"),
users.c.account_id,
func.row_number().over().label("index"), # type: ignore[no-untyped-call]
func.row_number().over().label("index"),
)
.select_from(users)
.cte("membership_fee_numbered_users")
Expand Down Expand Up @@ -289,7 +287,7 @@ def post_transactions_for_membership_fee(
numbered_transactions = (
select(
transactions.c.id,
func.row_number().over().label("index"), # type: ignore[no-untyped-call]
func.row_number().over().label("index"),
)
.select_from(transactions)
.cte("membership_fee_numbered_transactions")
Expand Down
24 changes: 16 additions & 8 deletions pycroft/lib/user_deletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
This module contains methods concerning user archival and deletion.
"""
from __future__ import annotations
import typing as t
from datetime import timedelta, datetime
from typing import Protocol, Sequence

Expand All @@ -24,6 +25,16 @@ class ArchivableMemberInfo(Protocol):
mem_end: datetime


TP = t.TypeVar("TP")
TO = t.TypeVar("TO")


# mrh, not available in py3.10…
class _WindowArgs(t.TypedDict, t.Generic[TP, TO]):
partition_by: TP
order_by: TO


def get_archivable_members(session: Session) -> Sequence[ArchivableMemberInfo]:
"""Return all the users that qualify for being archived right now.

Expand All @@ -33,28 +44,25 @@ def get_archivable_members(session: Session) -> Sequence[ArchivableMemberInfo]:
"""
# see FunctionElement.over
mem_ends_at = func.upper(Membership.active_during)
window_args = {
window_args: _WindowArgs = {
'partition_by': User.id,
'order_by': nulls_last(mem_ends_at),
}
# mypy: ignore[no-untyped-call]
last_mem = (
select(
User.id.label('user_id'),
func.last_value(Membership.id)
.over(**window_args, rows=(None, None)) # type: ignore[no-untyped-call]
.over(**window_args, rows=(None, None))
.label("mem_id"),
func.last_value(mem_ends_at)
.over(**window_args, rows=(None, None)) # type: ignore[no-untyped-call]
.over(**window_args, rows=(None, None))
.label("mem_end"),
)
.select_from(User)
.distinct()
.join(Membership)
.join(Config, Config.member_group_id == Membership.group_id)
).cte(
"last_mem"
) # mypy: ignore[no-untyped-call]
).cte("last_mem")
stmt = (
select(
User,
Expand All @@ -71,7 +79,7 @@ def get_archivable_members(session: Session) -> Sequence[ArchivableMemberInfo]:
# …and use that to filter out the `do-not-archive` occurrences.
.filter(CurrentProperty.property_name.is_(None))
.join(User, User.id == last_mem.c.user_id)
.filter(last_mem.c.mem_end < current_timestamp() - timedelta(days=14)) # type: ignore[no-untyped-call]
.filter(last_mem.c.mem_end < current_timestamp() - timedelta(days=14))
.order_by(last_mem.c.mem_end)
.options(joinedload(User.hosts), # joinedload(User.current_memberships),
joinedload(User.account, innerjoin=True), joinedload(User.room),
Expand Down
2 changes: 1 addition & 1 deletion requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ git+https://github.com/lukasjuhrich/sqlalchemy_schemadisplay.git@master#egg=sqla
sphinx~=5.1.1
sphinx-autobuild~=2021.3.14
git+https://github.com/agdsn/guzzle_sphinx_theme.git@977d49fcbdf2b3df9660d813d4b33369391923e1#egg=guzzle-sphinx-theme
mypy~=1.5.0
mypy~=1.8.0
celery-types~=0.9.3
types-jsonschema~=4.3.0
types-passlib~=1.7.7
Expand Down
1 change: 1 addition & 0 deletions scripts/run_mypy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# we don't want errexit
set -uo pipefail

mypy --version
mypy | tee mypy_results.log;
export mypy_status=$?
python ./scripts/render_mypy_results.py mypy_results.log
Expand Down
2 changes: 1 addition & 1 deletion web/blueprints/finance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ def balance_json(account_id: int) -> ResponseReturnValue:

sum_exp: ColumnElement[int] = t.cast(
Over[int],
func.sum(Split.amount).over(order_by=Transaction.valid_on), # type: ignore[no-untyped-call]
func.sum(Split.amount).over(order_by=Transaction.valid_on),
)

if invert:
Expand Down
5 changes: 1 addition & 4 deletions web/table/lazy_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ def __init__(self, glue: str = "") -> None:
self.glue = glue

def __call__(self, func: DecoratedInType) -> DecoratedOutType:
# error: Argument 1 to "__call__" of "IdentityFunction" has incompatible type
# "Callable[_P, LazilyJoined]"; expected "Callable[_P, LazilyJoined]" [arg-type]
# …go home mypy, you're drunk!
@wraps(func) # type: ignore[arg-type]
@wraps(func)
def wrapped(*a: _P.args, **kw: _P.kwargs) -> LazilyJoined:
return LazilyJoined(func(*a, **kw), glue=self.glue)

Expand Down
Loading