Skip to content

Commit

Permalink
type hint updates, flask-sqlalchemy updates
Browse files Browse the repository at this point in the history
  • Loading branch information
le717 committed Nov 21, 2022
1 parent e1d4faa commit 542fee0
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion db/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def process_revision_directives(context, revision, directives):
context.configure(
connection=connection,
target_metadata=target_metadata,
process_revision_directives=process_revision_directives
process_revision_directives=process_revision_directives,
)

with context.begin_transaction():
Expand Down
8 changes: 5 additions & 3 deletions src/core/database/linkrot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from typing import Literal, TypedDict, Union
from typing import Literal, TypedDict

import requests
import sys_vars
Expand Down Expand Up @@ -38,7 +38,7 @@ def __ping_url(url: str) -> bool:
return False


def __ping_wayback_machine(url: str) -> Union[Literal[False], str]:
def __ping_wayback_machine(url: str) -> Literal[False] | str:
"""Check the Web Archive for an archived URL."""
r = requests.get(f"https://archive.org/wayback/available?url={url}").json()
if not r["archived_snapshots"]:
Expand All @@ -55,7 +55,9 @@ def __create(data: WebLink) -> Literal[True]:


def __get(uuid: str) -> RottedLinks:
return RottedLinks.query.filter_by(id=uuid).first()
return (
db.session.execute(db.select(RottedLinks).filter_by(id=uuid)).scalars().first()
)


def __update(data: RottedLinks) -> Literal[True]:
Expand Down
4 changes: 2 additions & 2 deletions src/core/database/weblink.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def exists(uuid: str) -> bool:

def get(uuid: str) -> Optional[WebLink]:
"""Get a single weblink."""
return WebLink.query.filter_by(id=uuid).first()
return db.session.execute(db.select(WebLink).filter_by(id=uuid)).scalars().first()


def get_all(with_rotted: bool = False, **kwargs: Any) -> list[WebLink]:
Expand All @@ -72,7 +72,7 @@ def get_all(with_rotted: bool = False, **kwargs: Any) -> list[WebLink]:
# Remove all rotted links
if not with_rotted:
filters.append(WebLink.is_dead != "1")
wbs = WebLink.query.filter(*filters).all()
wbs = db.session.execute(db.select(WebLink).filter(*filters)).scalars().all()

# Adjust the title of the link depending on status
for wb in wbs:
Expand Down
1 change: 0 additions & 1 deletion src/core/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
from logging.handlers import RotatingFileHandler
from pathlib import Path
from typing import Union

from flask import request
import requests
Expand Down
6 changes: 3 additions & 3 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from urllib.parse import urlencode
from typing import Any, Union
from typing import Any


__all__ = [
Expand All @@ -27,11 +27,11 @@ def authed_request(*args: str, **kwargs: Any) -> str:
return f"{endpoint}?{__auth_key(kwargs['auth'])}".replace("//", "/")


def from_json(data: str) -> Union[dict, list]:
def from_json(data: str) -> dict | list:
return json.loads(data)


def to_json(data: Union[dict, list]) -> str:
def to_json(data: dict | list) -> str:
return json.dumps(data)


Expand Down

0 comments on commit 542fee0

Please sign in to comment.