Fix mypy errors introduced in b007afc901

This commit is contained in:
Jonas Schäfer
2021-05-27 16:33:46 +02:00
parent 28e01c336d
commit 13b2a76c3d
6 changed files with 36 additions and 37 deletions

View File

@@ -195,25 +195,25 @@ def create_app() -> quart.Quart:
app.context_processor(proc)
app.register_error_handler(
aiohttp.ClientConnectorError,
backend_error_handler,
backend_error_handler, # type:ignore
)
app.register_error_handler(
quart.exceptions.HTTPException,
generic_http_error,
generic_http_error, # type:ignore
)
app.register_error_handler(
Exception,
generic_error_handler,
generic_error_handler, # type:ignore
)
@app.route("/") # type: ignore
@app.route("/")
async def index() -> quart.Response:
if infra.client.has_session:
return redirect(url_for('user.index'))
return redirect(url_for('main.login'))
@app.route("/site.webmanifest") # type: ignore
@app.route("/site.webmanifest")
def site_manifest() -> quart.Response:
# this is needed for icons
return jsonify(

View File

@@ -28,7 +28,7 @@ from .infra import client, circle_name, BaseForm
bp = Blueprint("admin", __name__, url_prefix="/admin")
@bp.route("/") # type:ignore
@bp.route("/")
@client.require_admin_session()
async def index() -> str:
return await render_template("admin_home.html")
@@ -38,7 +38,7 @@ class PasswordResetLinkPost(BaseForm):
action_revoke = wtforms.StringField()
@bp.route("/users") # type:ignore
@bp.route("/users")
@client.require_admin_session()
async def users() -> str:
users = sorted(
@@ -88,7 +88,7 @@ class EditUserForm(BaseForm):
)
@bp.route("/user/<localpart>/", methods=["GET", "POST"]) # type:ignore
@bp.route("/user/<localpart>/", methods=["GET", "POST"])
@client.require_admin_session()
async def edit_user(localpart: str) -> typing.Union[quart.Response, str]:
target_user_info = await client.get_user_by_localpart(localpart)
@@ -143,7 +143,7 @@ class DeleteUserForm(BaseForm):
)
@bp.route("/user/<localpart>/delete", methods=["GET", "POST"]) # type:ignore
@bp.route("/user/<localpart>/delete", methods=["GET", "POST"])
@client.require_admin_session()
async def delete_user(localpart: str) -> typing.Union[str, quart.Response]:
target_user_info = await client.get_user_by_localpart(localpart)
@@ -164,7 +164,7 @@ async def delete_user(localpart: str) -> typing.Union[str, quart.Response]:
)
@bp.route("/user/<localpart>/debug") # type:ignore
@bp.route("/user/<localpart>/debug")
@client.require_admin_session()
async def debug_user(localpart: str) -> typing.Union[str, quart.Response]:
target_user_info = await client.get_user_by_localpart(localpart)
@@ -180,7 +180,7 @@ async def debug_user(localpart: str) -> typing.Union[str, quart.Response]:
)
@bp.route("/users/password-reset/<id_>", methods=["GET", "POST"]) # type:ignore # noqa:E501
@bp.route("/users/password-reset/<id_>", methods=["GET", "POST"])
@client.require_admin_session()
async def user_password_reset_link(
id_: str,
@@ -274,7 +274,7 @@ class InvitePost(BaseForm):
)
@bp.route("/invitations", methods=["GET", "POST"]) # type:ignore
@bp.route("/invitations", methods=["GET", "POST"])
@client.require_admin_session()
async def invitations() -> typing.Union[str, quart.Response]:
invites = sorted(
@@ -320,7 +320,7 @@ class InviteForm(BaseForm):
)
@bp.route("/invitation/-/new", methods=["POST"]) # type:ignore
@bp.route("/invitation/-/new", methods=["POST"])
@client.require_admin_session()
async def create_invite() -> typing.Union[str, quart.Response]:
form = InvitePost()
@@ -348,7 +348,7 @@ async def create_invite() -> typing.Union[str, quart.Response]:
invite_form=form)
@bp.route("/invitation/<id_>", methods=["GET", "POST"]) # type:ignore
@bp.route("/invitation/<id_>", methods=["GET", "POST"])
@client.require_admin_session()
async def edit_invite(id_: str) -> typing.Union[str, quart.Response]:
try:
@@ -397,7 +397,7 @@ class CirclePost(BaseForm):
)
@bp.route("/circles") # type:ignore
@bp.route("/circles")
@client.require_admin_session()
async def circles() -> str:
circles = sorted(
@@ -414,7 +414,7 @@ async def circles() -> str:
)
@bp.route("/circle/-/new", methods=["POST"]) # type:ignore
@bp.route("/circle/-/new", methods=["POST"])
@client.require_admin_session()
async def create_circle() -> typing.Union[str, quart.Response]:
create_form = CirclePost()
@@ -460,7 +460,7 @@ class EditCircleForm(BaseForm):
)
@bp.route("/circle/<id_>", methods=["GET", "POST"]) # type:ignore
@bp.route("/circle/<id_>", methods=["GET", "POST"])
@client.require_admin_session()
async def edit_circle(id_: str) -> typing.Union[str, quart.Response]:
async with client.authenticated_session() as session:

View File

@@ -46,12 +46,12 @@ def context() -> typing.Mapping[str, typing.Any]:
}
@bp.route("/<id_>") # type:ignore
@bp.route("/<id_>")
async def view_old(id_: str) -> quart.Response:
return redirect(url_for(".view", id_=id_))
@bp.route("/<id_>/") # type:ignore
@bp.route("/<id_>/")
async def view(id_: str) -> typing.Union[quart.Response,
typing.Tuple[str, int],
str]:
@@ -124,7 +124,7 @@ class RegisterForm(BaseForm):
)
@bp.route("/<id_>/register", methods=["GET", "POST"]) # type:ignore
@bp.route("/<id_>/register", methods=["GET", "POST"])
async def register(id_: str) -> typing.Union[str, quart.Response]:
try:
invite = await client.get_public_invite_by_id(id_)
@@ -191,7 +191,7 @@ class ResetForm(BaseForm):
)
@bp.route("/<id_>/reset", methods=["GET", "POST"]) # type:ignore
@bp.route("/<id_>/reset", methods=["GET", "POST"])
async def reset(id_: str) -> typing.Union[str, quart.Response]:
try:
invite = await client.get_public_invite_by_id(id_)
@@ -232,7 +232,7 @@ async def reset(id_: str) -> typing.Union[str, quart.Response]:
)
@bp.route("/success", methods=["GET", "POST"]) # type:ignore
@bp.route("/success", methods=["GET", "POST"])
async def success() -> str:
return await render_template(
"invite_success.html",
@@ -240,7 +240,7 @@ async def success() -> str:
)
@bp.route("/success/reset", methods=["GET", "POST"]) # type:ignore
@bp.route("/success/reset", methods=["GET", "POST"])
async def reset_success() -> str:
return await render_template(
"invite_reset_success.html",
@@ -248,6 +248,6 @@ async def reset_success() -> str:
)
@bp.route("/-") # type:ignore
@bp.route("/-")
async def index() -> quart.Response:
return redirect(url_for("index"))

View File

@@ -47,7 +47,7 @@ class LoginForm(BaseForm):
)
@bp.route("/-") # type:ignore
@bp.route("/-")
async def index() -> quart.Response:
return redirect(url_for("index"))
@@ -55,7 +55,7 @@ async def index() -> quart.Response:
ERR_CREDENTIALS_INVALID = _l("Invalid username or password.")
@bp.route("/login", methods=["GET", "POST"]) # type:ignore
@bp.route("/login", methods=["GET", "POST"])
async def login() -> typing.Union[str, quart.Response]:
if client.has_session and (await client.test_session()):
return redirect(url_for('user.index'))
@@ -88,7 +88,7 @@ async def login() -> typing.Union[str, quart.Response]:
return await render_template("login.html", form=form)
@bp.route("/meta/about.html") # type:ignore
@bp.route("/meta/about.html")
async def about() -> str:
version = None
extra_versions = {}
@@ -112,7 +112,7 @@ async def about() -> str:
)
@bp.route("/meta/demo.html") # type:ignore
@bp.route("/meta/demo.html")
async def demo() -> str:
return await render_template("demo.html")
@@ -121,7 +121,7 @@ def repad(s: str) -> str:
return s + "=" * (4 - len(s) % 4)
@bp.route("/avatar/<from_>/<code>") # type:ignore
@bp.route("/avatar/<from_>/<code>")
async def avatar(from_: str, code: str) -> quart.Response:
etag: typing.Optional[str]
try:
@@ -165,6 +165,6 @@ async def avatar(from_: str, code: str) -> quart.Response:
return response
@bp.route("/_health") # type:ignore
@bp.route("/_health")
async def health() -> Response:
return Response("STATUS OK", content_type="text/plain")

View File

@@ -271,9 +271,8 @@ class ProsodyClient:
def init_app(self, app: quart.Quart) -> None:
app.config[self.CONFIG_ENDPOINT]
# the type annotation in quart seems to be wrong here
app.teardown_appcontext(self._plain_session.teardown) # type:ignore
app.teardown_appcontext(self._auth_session.teardown) # type:ignore
app.teardown_appcontext(self._plain_session.teardown)
app.teardown_appcontext(self._auth_session.teardown)
@property
def _endpoint_base(self) -> str:

View File

@@ -75,14 +75,14 @@ class ProfileForm(BaseForm):
)
@bp.route("/") # type:ignore
@bp.route("/")
@client.require_session()
async def index() -> str:
user_info = await client.get_user_info()
return await render_template("user_home.html", user_info=user_info)
@bp.route('/passwd', methods=["GET", "POST"]) # type:ignore
@bp.route('/passwd', methods=["GET", "POST"])
@client.require_session()
async def change_pw() -> typing.Union[str, quart.Response]:
form = ChangePasswordForm()
@@ -114,7 +114,7 @@ EAVATARTOOBIG = _l(
)
@bp.route("/profile", methods=["GET", "POST"]) # type:ignore
@bp.route("/profile", methods=["GET", "POST"])
@client.require_session()
async def profile() -> typing.Union[str, quart.Response]:
max_avatar_size = current_app.config["MAX_AVATAR_SIZE"]
@@ -168,7 +168,7 @@ async def profile() -> typing.Union[str, quart.Response]:
avatar_too_big_warning=EAVATARTOOBIG)
@bp.route("/logout", methods=["GET", "POST"]) # type:ignore
@bp.route("/logout", methods=["GET", "POST"])
@client.require_session()
async def logout() -> typing.Union[quart.Response, str]:
form = LogoutForm()