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 to python 3.11 #690

Merged
merged 7 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
4 changes: 2 additions & 2 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fetch-depth: 50
- uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.11'
cache: 'pip'
- name: "Run pre-commit hooks for HEAD"
uses: pre-commit/[email protected]
Expand All @@ -39,7 +39,7 @@ jobs:
submodules: recursive
- uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.11'
cache: 'pip'
- name: print information about pip cache
run: pip cache info && pip cache list
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
rev: v2.29.0
hooks:
- id: pyupgrade
args: ["--py310-plus"]
args: ["--py311-plus"]
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.254'
Expand Down
2 changes: 1 addition & 1 deletion docker/base.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This file is part of the Pycroft project and licensed under the terms of
# the Apache License, Version 2.0. See the LICENSE file for details.

FROM python:3.10-bullseye
FROM python:3.11-bookworm
ARG UID=1000
ARG GID=1000
ENV LANG=C.UTF-8 DEBIAN_FRONTEND=noninteractive
Expand Down
1 change: 1 addition & 0 deletions docker/dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ RUN apt-get update \
less \
libpq-dev \
nodejs \
npm \
postgresql-client \
strace \
unzip \
Expand Down
2 changes: 1 addition & 1 deletion docker/dev/container/hooks/init/10_venv
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ function execute_hook() {
if [[ ! -f /opt/pycroft/venv/bin/activate ]]; then
echo "Creating virtual environment"
python3 -m venv /opt/pycroft/venv
/opt/pycroft/venv/bin/python -m ensurepip
fi

if $PY -c 'import importlib.util as u; exit(0 if u.find_spec("pycroft") is not None else 1)'; then
echo "Pip packages present, nothing to do"
return
fi

$PY -m ensurepip
$PIP install wheel

echo "No pip packages found, installing requirements"
Expand Down
4 changes: 0 additions & 4 deletions ldap_sync/concepts/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ def _maybe_escape_filter_chars(value: T) -> T | str:
return value


# TODO: replace with the py3.11 Self type
TRecord = typing.TypeVar("TRecord", bound="Record")


def escape_and_normalize_attrs(attrs: Attributes) -> NormalizedAttributes:
return {
key: [
Expand Down
7 changes: 2 additions & 5 deletions pycroft/helpers/i18n/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import json
import traceback
import typing
import typing as t
from functools import partial

import jsonschema
Expand All @@ -21,10 +22,6 @@
from .serde import Serializable, serialize_param, deserialize_param


# TODO remove in py3.11 (replace `TSelf` by `Self`)
TMessage = typing.TypeVar("TMessage", bound="Message")


class Message(abc.ABC):
__slots__ = ("domain", "args", "kwargs")

Expand Down Expand Up @@ -91,7 +88,7 @@ def to_json(self) -> str:
obj["kwargs"] = {k: serialize_param(v) for k, v in self.kwargs.items()}
return json.dumps(obj, ensure_ascii=False)

def format(self: TMessage, *args: Serializable, **kwargs: Serializable) -> TMessage:
def format(self, *args: Serializable, **kwargs: Serializable) -> t.Self:
self.args = args
self.kwargs = kwargs
return self
Expand Down
4 changes: 3 additions & 1 deletion pycroft/helpers/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from itertools import tee, chain, filterfalse
from typing import Generic

# from typing_extensions import Self

if t.TYPE_CHECKING:
from _typeshed import SupportsAllComparisons
# TODO figure out how we can demand that T shall be a totally ordered metric space
Expand Down Expand Up @@ -202,7 +204,7 @@ def from_explicit_data(
cls,
lower: T | None, lower_closed: bool,
upper: T | None, upper_closed: bool,
) -> Interval[T]:
) -> t.Self:
return cls(Bound(_convert_begin(lower), lower_closed),
Bound(_convert_end(upper), upper_closed))

Expand Down
3 changes: 2 additions & 1 deletion pycroft/lib/finance/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import logging
import re
import typing as t
from typing import Callable, TypeVar
from typing import TypeVar
from collections.abc import Callable

from sqlalchemy import select
from sqlalchemy.orm import joinedload
Expand Down
3 changes: 2 additions & 1 deletion pycroft/lib/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import typing as t
from abc import ABC, abstractmethod
from datetime import datetime
from typing import Mapping, TypeVar, Generic
from typing import TypeVar, Generic
from collections.abc import Mapping

from marshmallow import ValidationError
from sqlalchemy import select, func
Expand Down
2 changes: 1 addition & 1 deletion pycroft/lib/user.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015 The Pycroft Authors. See the AUTHORS file.

Check warning on line 1 in pycroft/lib/user.py

View workflow job for this annotation

GitHub Actions / python-lint

Warning

docstring of pycroft.lib.user.edit_email:8: Field list ends without a blank line; unexpected unindent.

Check warning on line 1 in pycroft/lib/user.py

View workflow job for this annotation

GitHub Actions / python-lint

Warning

docstring of pycroft.lib.user.edit_birthdate:5: Field list ends without a blank line; unexpected unindent.
# This file is part of the Pycroft project and licensed under the terms of
# the Apache License, Version 2.0. See the LICENSE file for details.
"""
Expand All @@ -15,7 +15,7 @@
import typing as t
from datetime import timedelta, date
from difflib import SequenceMatcher
from typing import Iterable
from collections.abc import Iterable

from sqlalchemy import func, select, Boolean, String, ColumnElement, ScalarResult
from sqlalchemy.orm import Session
Expand Down
3 changes: 2 additions & 1 deletion pycroft/lib/user_deletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from __future__ import annotations
import typing as t
from datetime import timedelta, datetime
from typing import Protocol, Sequence
from typing import Protocol
from collections.abc import Sequence

from sqlalchemy import func, nulls_last, and_, not_
from sqlalchemy.future import select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
Create Date: 2019-10-03 19:15:55.716640
"""
from typing import Callable

from collections.abc import Callable

import sqlalchemy as sa
from alembic import op
Expand Down
5 changes: 2 additions & 3 deletions pycroft/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
:copyright: (c) 2011 by AG DSN.
"""
import re
import typing as t

import ipaddr
from sqlalchemy import String
Expand Down Expand Up @@ -101,10 +102,8 @@ def __str__(self):
# DeprecationWarning)
q: Query

T = typing.TypeVar('T', bound='ModelBase')

@classmethod
def get(cls: type[T], *a, **kw) -> T: # noqa: F811
def get(cls, *a, **kw) -> t.Self: # noqa: F811
pass


Expand Down
3 changes: 2 additions & 1 deletion pycroft/model/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
:copyright: (c) 2011 by AG DSN.
"""
import typing as t
from typing import overload, TypeVar, Callable, Any, TYPE_CHECKING
from typing import overload, TypeVar, Any, TYPE_CHECKING
from collections.abc import Callable

from sqlalchemy.orm import scoped_session
from sqlalchemy.sql.functions import AnsiFunction
Expand Down
3 changes: 2 additions & 1 deletion pycroft/model/task_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"""
from dataclasses import dataclass
from datetime import date
from typing import Callable, TypeVar
from typing import TypeVar
from collections.abc import Callable

import wrapt
from marshmallow import Schema, fields, post_load, ValidationError
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"
[tool.mypy]
exclude = "deps/.*/build"
plugins = "sqlalchemy.ext.mypy.plugin"
python_version = "3.10"
python_version = "3.11"
follow_imports = "silent"
ignore_missing_imports = true
# this list shall slowly grow until it covers the whole codebase.
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ blinker~=1.4
ipaddr~=2.2.0
jsonschema~=3.2.0
passlib~=1.7.1
psycopg2~=2.8.6
psycopg2-binary~=2.9.4
webargs~=8.3.0
wrapt~=1.12.1
wrapt~=1.14.1
# only needed for ldap caching
ldap3~=2.5.1
celery~=5.2.1
Expand Down
3 changes: 2 additions & 1 deletion scripts/render_mypy_results.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import re
import typing as t
from typing import NamedTuple

RE_OUTPUT_LINE = re.compile(
Expand All @@ -15,7 +16,7 @@ class MypyMessage(NamedTuple):
message: str

@classmethod
def from_mypy_output(cls, output: str) -> MypyMessage | None:
def from_mypy_output(cls, output: str) -> t.Self | None:
match = RE_OUTPUT_LINE.match(output)
if match is None:
return None
Expand Down
3 changes: 2 additions & 1 deletion scripts/render_sphinx_log.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations
import typing as t
from typing import NamedTuple


Expand All @@ -10,7 +11,7 @@ class SphinxLog(NamedTuple):
message: str

@classmethod
def from_sphinx_output(cls, line: str) -> SphinxLog | None:
def from_sphinx_output(cls, line: str) -> t.Self | None:
args = tuple(el.strip() for el in line.split(":", maxsplit=4))
if len(args) != 5:
return None
Expand Down
2 changes: 1 addition & 1 deletion scripts/server_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
import sys
import time
from typing import Callable
from collections.abc import Callable

from babel.support import Translations
from flask import g, request
Expand Down
2 changes: 1 addition & 1 deletion web/blueprints/facilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def building_level_rooms_json(
.filter(and_(Room.building == building, Room.level == level))
.outerjoin(user, user_join_condition))

level_inhabitants: dict[Room, list[User]] = defaultdict(lambda: [])
level_inhabitants: dict[Room, list[User]] = defaultdict(list)
for room, user in rooms_users_q.all():
if user is not None:
level_inhabitants[room].append(t.cast(User, user))
Expand Down
2 changes: 1 addition & 1 deletion web/blueprints/facilities/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is part of the Pycroft project and licensed under the terms of
# the Apache License, Version 2.0. See the LICENSE file for details.
import typing as t
from typing import Callable
from collections.abc import Callable

from flask import url_for
from flask_wtf import FlaskForm as Form
Expand Down
3 changes: 2 additions & 1 deletion web/blueprints/user/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from datetime import timedelta
from decimal import Decimal
from functools import partial
from typing import TypeVar, Callable, cast
from typing import TypeVar, cast
from collections.abc import Callable

from flask import (
Blueprint,
Expand Down
3 changes: 2 additions & 1 deletion web/table/lazy_join.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import typing as t
from functools import wraps
from types import FunctionType
from typing import Generator, Callable, overload
from typing import overload
from collections.abc import Generator, Callable


_T = t.TypeVar("_T")
Expand Down
3 changes: 2 additions & 1 deletion web/table/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from dataclasses import dataclass
from datetime import date, datetime, time, timezone
from operator import methodcaller
from typing import Iterable, Any, Callable
from typing import Any
from collections.abc import Iterable, Callable
from urllib.parse import urlparse, parse_qsl, urlencode, urlunparse

from annotated_types import Predicate
Expand Down
Loading