1
0
mirror of synced 2025-02-17 11:18:33 +01:00

Fix some new typing errors (a bunch of ignores can be removed!), black errors.

This commit is contained in:
Jennifer Taylor 2024-03-30 02:07:21 +00:00
parent 223c93874c
commit f63247b605
19 changed files with 131 additions and 107 deletions

View File

@ -177,7 +177,7 @@ class JubeatBase(CoreHandler, CardManagerHandler, PASELIHandler, Base):
else: else:
# We will want to fetch the remaining scores that were in our # We will want to fetch the remaining scores that were in our
# cache. # cache.
scores = self.cache.get(cache_key) # type: ignore scores = self.cache.get(cache_key)
if len(scores) < 50: if len(scores) < 50:
# We simply return the whole amount for this, and cache nothing. # We simply return the whole amount for this, and cache nothing.

View File

@ -530,10 +530,14 @@ class JubeatFesto(
], ],
[ [
( (
80000034 (
if dataver < 2020062900 80000034
else ( if dataver < 2020062900
30000108 if dataver < 2020091300 else (40000107 if dataver < 2021020100 else 30000004) else (
30000108
if dataver < 2020091300
else (40000107 if dataver < 2021020100 else 30000004)
)
), ),
0, 0,
), ),

View File

@ -335,12 +335,12 @@ class GlobalMusicData(BaseGlobalData):
{ {
"rank": self.__max(oldscore.data["rank"], newscore.data["rank"]), "rank": self.__max(oldscore.data["rank"], newscore.data["rank"]),
"halo": self.__max(oldscore.data["halo"], newscore.data["halo"]), "halo": self.__max(oldscore.data["halo"], newscore.data["halo"]),
"ghost": oldscore.data.get("ghost") "ghost": (
if oldscore.points > newscore.points oldscore.data.get("ghost") if oldscore.points > newscore.points else newscore.data.get("ghost")
else newscore.data.get("ghost"), ),
"trace": oldscore.data.get("trace") "trace": (
if oldscore.points > newscore.points oldscore.data.get("trace") if oldscore.points > newscore.points else newscore.data.get("trace")
else newscore.data.get("trace"), ),
"combo": self.__max(oldscore.data["combo"], newscore.data["combo"]), "combo": self.__max(oldscore.data["combo"], newscore.data["combo"]),
}, },
) )
@ -360,19 +360,23 @@ class GlobalMusicData(BaseGlobalData):
oldscore.plays + newscore.plays, oldscore.plays + newscore.plays,
{ {
"clear_status": self.__max(oldscore.data["clear_status"], newscore.data["clear_status"]), "clear_status": self.__max(oldscore.data["clear_status"], newscore.data["clear_status"]),
"ghost": oldscore.data.get("ghost") "ghost": (
if oldscore.points > newscore.points oldscore.data.get("ghost") if oldscore.points > newscore.points else newscore.data.get("ghost")
else newscore.data.get("ghost"), ),
"miss_count": self.__min( "miss_count": self.__min(
oldscore.data.get_int("miss_count", -1), oldscore.data.get_int("miss_count", -1),
newscore.data.get_int("miss_count", -1), newscore.data.get_int("miss_count", -1),
), ),
"pgreats": oldscore.data.get_int("pgreats", -1) "pgreats": (
if oldscore.points > newscore.points oldscore.data.get_int("pgreats", -1)
else newscore.data.get_int("pgreats", -1), if oldscore.points > newscore.points
"greats": oldscore.data.get_int("greats", -1) else newscore.data.get_int("pgreats", -1)
if oldscore.points > newscore.points ),
else newscore.data.get_int("greats", -1), "greats": (
oldscore.data.get_int("greats", -1)
if oldscore.points > newscore.points
else newscore.data.get_int("greats", -1)
),
}, },
) )
@ -392,9 +396,9 @@ class GlobalMusicData(BaseGlobalData):
oldscore.location, # Always propagate location from local setup if possible oldscore.location, # Always propagate location from local setup if possible
oldscore.plays + newscore.plays, oldscore.plays + newscore.plays,
{ {
"ghost": oldscore.data.get("ghost") "ghost": (
if oldscore.points > newscore.points oldscore.data.get("ghost") if oldscore.points > newscore.points else newscore.data.get("ghost")
else newscore.data.get("ghost"), ),
"combo": self.__max(oldscore.data["combo"], newscore.data["combo"]), "combo": self.__max(oldscore.data["combo"], newscore.data["combo"]),
"medal": self.__max(oldscore.data["medal"], newscore.data["medal"]), "medal": self.__max(oldscore.data["medal"], newscore.data["medal"]),
# Conditionally include this if we have any info for it. # Conditionally include this if we have any info for it.

View File

@ -1,6 +1,6 @@
import copy import copy
import os import os
from sqlalchemy.engine import Engine # type: ignore from sqlalchemy.engine import Engine
from typing import Any, Dict, Optional, Set from typing import Any, Dict, Optional, Set
from bemani.common import GameConstants, RegionConstants from bemani.common import GameConstants, RegionConstants

View File

@ -2,13 +2,13 @@ import os
import alembic.config import alembic.config
from alembic.migration import MigrationContext from alembic.migration import MigrationContext
from alembic.autogenerate import compare_metadata # type: ignore from alembic.autogenerate import compare_metadata
from sqlalchemy import create_engine # type: ignore from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session # type: ignore from sqlalchemy.orm import scoped_session
from sqlalchemy.orm import sessionmaker from sqlalchemy.orm import sessionmaker
from sqlalchemy.engine import Engine # type: ignore from sqlalchemy.engine import Engine
from sqlalchemy.sql import text # type: ignore from sqlalchemy.sql import text
from sqlalchemy.exc import ProgrammingError # type: ignore from sqlalchemy.exc import ProgrammingError
from bemani.data.api.user import GlobalUserData from bemani.data.api.user import GlobalUserData
from bemani.data.api.game import GlobalGameData from bemani.data.api.game import GlobalGameData
@ -153,7 +153,7 @@ class Data:
] ]
alembicArgs.extend(args) alembicArgs.extend(args)
os.chdir(base_dir) os.chdir(base_dir)
alembic.config.main(argv=alembicArgs) # type: ignore alembic.config.main(argv=alembicArgs)
def create(self) -> None: def create(self) -> None:
""" """

View File

@ -1,6 +1,6 @@
import uuid import uuid
from sqlalchemy import Table, Column # type: ignore from sqlalchemy import Table, Column
from sqlalchemy.types import String, Integer # type: ignore from sqlalchemy.types import String, Integer
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional
from bemani.common import Time from bemani.common import Time

View File

@ -6,11 +6,11 @@ from typing_extensions import Final
from bemani.common import Time from bemani.common import Time
from bemani.data.config import Config from bemani.data.config import Config
from sqlalchemy.engine.base import Connection # type: ignore
from sqlalchemy.engine import CursorResult # type: ignore from sqlalchemy.engine import CursorResult # type: ignore
from sqlalchemy.sql import text # type: ignore from sqlalchemy.orm import scoped_session
from sqlalchemy.types import String, Integer # type: ignore from sqlalchemy.sql import text
from sqlalchemy import Table, Column, MetaData # type: ignore from sqlalchemy.types import String, Integer
from sqlalchemy import Table, Column, MetaData
metadata = MetaData() metadata = MetaData()
@ -40,7 +40,7 @@ class _BytesEncoder(json.JSONEncoder):
class BaseData: class BaseData:
SESSION_LENGTH: Final[int] = 32 SESSION_LENGTH: Final[int] = 32
def __init__(self, config: Config, conn: Connection) -> None: def __init__(self, config: Config, conn: scoped_session) -> None:
""" """
Initialize any DB singleton. Initialize any DB singleton.

View File

@ -1,6 +1,6 @@
from sqlalchemy import Table, Column, UniqueConstraint # type: ignore from sqlalchemy import Table, Column, UniqueConstraint
from sqlalchemy.types import String, Integer, JSON # type: ignore from sqlalchemy.types import String, Integer, JSON
from sqlalchemy.dialects.mysql import BIGINT as BigInteger # type: ignore from sqlalchemy.dialects.mysql import BIGINT as BigInteger
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional
from bemani.common import GameConstants, ValidatedDict, Time from bemani.common import GameConstants, ValidatedDict, Time

View File

@ -1,8 +1,8 @@
import copy import copy
from sqlalchemy import Table, Column, UniqueConstraint # type: ignore from sqlalchemy import Table, Column, UniqueConstraint
from sqlalchemy.types import String, Integer, JSON # type: ignore from sqlalchemy.types import String, Integer, JSON
from sqlalchemy.dialects.mysql import BIGINT as BigInteger # type: ignore from sqlalchemy.dialects.mysql import BIGINT as BigInteger
from typing import Optional, Dict, List, Tuple, Any from typing import Optional, Dict, List, Tuple, Any
from bemani.common import GameConstants, ValidatedDict, Time from bemani.common import GameConstants, ValidatedDict, Time

View File

@ -1,6 +1,6 @@
from sqlalchemy import Table, Column, UniqueConstraint # type: ignore from sqlalchemy import Table, Column, UniqueConstraint
from sqlalchemy.types import String, Integer, JSON # type: ignore from sqlalchemy.types import String, Integer, JSON
from sqlalchemy.dialects.mysql import BIGINT as BigInteger # type: ignore from sqlalchemy.dialects.mysql import BIGINT as BigInteger
from typing import Optional, Dict, List, Tuple, Any from typing import Optional, Dict, List, Tuple, Any
from typing_extensions import Final from typing_extensions import Final

View File

@ -1,7 +1,7 @@
from sqlalchemy import Table, Column, UniqueConstraint # type: ignore from sqlalchemy import Table, Column, UniqueConstraint
from sqlalchemy.exc import IntegrityError # type: ignore from sqlalchemy.exc import IntegrityError
from sqlalchemy.types import String, Integer, JSON # type: ignore from sqlalchemy.types import String, Integer, JSON
from sqlalchemy.dialects.mysql import BIGINT as BigInteger # type: ignore from sqlalchemy.dialects.mysql import BIGINT as BigInteger
from typing import Optional, Dict, List, Tuple, Any from typing import Optional, Dict, List, Tuple, Any
from bemani.common import GameConstants, Time from bemani.common import GameConstants, Time

View File

@ -1,6 +1,6 @@
from sqlalchemy import Table, Column, UniqueConstraint # type: ignore from sqlalchemy import Table, Column, UniqueConstraint
from sqlalchemy.types import String, Integer, Text, JSON # type: ignore from sqlalchemy.types import String, Integer, Text, JSON
from sqlalchemy.dialects.mysql import BIGINT as BigInteger # type: ignore from sqlalchemy.dialects.mysql import BIGINT as BigInteger
from typing import Optional, Dict, List, Tuple, Any from typing import Optional, Dict, List, Tuple, Any
from bemani.common import GameConstants, Time from bemani.common import GameConstants, Time

View File

@ -1,8 +1,8 @@
import random import random
from sqlalchemy import Table, Column, UniqueConstraint # type: ignore from sqlalchemy import Table, Column, UniqueConstraint
from sqlalchemy.types import String, Integer, JSON # type: ignore from sqlalchemy.types import String, Integer, JSON
from sqlalchemy.dialects.mysql import BIGINT as BigInteger # type: ignore from sqlalchemy.dialects.mysql import BIGINT as BigInteger
from sqlalchemy.exc import IntegrityError # type: ignore from sqlalchemy.exc import IntegrityError
from typing import Optional, Dict, List, Tuple, Any from typing import Optional, Dict, List, Tuple, Any
from typing_extensions import Final from typing_extensions import Final
from passlib.hash import pbkdf2_sha512 # type: ignore from passlib.hash import pbkdf2_sha512 # type: ignore

View File

@ -377,12 +377,14 @@ class AP2PlaceObjectTag(Tag):
"blend": self.blend, "blend": self.blend,
"update": self.update, "update": self.update,
"transform": self.transform.as_dict(*args, **kwargs) if self.transform is not None else None, "transform": self.transform.as_dict(*args, **kwargs) if self.transform is not None else None,
"rotation_origin": self.rotation_origin.as_dict(*args, **kwargs) "rotation_origin": (
if self.rotation_origin is not None self.rotation_origin.as_dict(*args, **kwargs) if self.rotation_origin is not None else None
else None, ),
"projection": "none" "projection": (
if self.projection == self.PROJECTION_NONE "none"
else ("affine" if self.projection == self.PROJECTION_AFFINE else "perspective"), if self.projection == self.PROJECTION_NONE
else ("affine" if self.projection == self.PROJECTION_AFFINE else "perspective")
),
"mult_color": self.mult_color.as_dict(*args, **kwargs) if self.mult_color is not None else None, "mult_color": self.mult_color.as_dict(*args, **kwargs) if self.mult_color is not None else None,
"add_color": self.add_color.as_dict(*args, **kwargs) if self.add_color is not None else None, "add_color": self.add_color.as_dict(*args, **kwargs) if self.add_color is not None else None,
"hsl_shift": self.hsl_shift.as_dict(*args, **kwargs) if self.hsl_shift else None, "hsl_shift": self.hsl_shift.as_dict(*args, **kwargs) if self.hsl_shift else None,

View File

@ -175,15 +175,17 @@ def viewevents() -> Response:
"refresh": url_for("admin_pages.listevents", since=-1), "refresh": url_for("admin_pages.listevents", since=-1),
"backfill": url_for("admin_pages.backfillevents", until=-1), "backfill": url_for("admin_pages.backfillevents", until=-1),
"viewuser": url_for("admin_pages.viewuser", userid=-1), "viewuser": url_for("admin_pages.viewuser", userid=-1),
"jubeatsong": url_for("jubeat_pages.viewtopscores", musicid=-1) "jubeatsong": (
if GameConstants.JUBEAT in g.config.support url_for("jubeat_pages.viewtopscores", musicid=-1) if GameConstants.JUBEAT in g.config.support else None
else None, ),
"iidxsong": url_for("iidx_pages.viewtopscores", musicid=-1) "iidxsong": (
if GameConstants.IIDX in g.config.support url_for("iidx_pages.viewtopscores", musicid=-1) if GameConstants.IIDX in g.config.support else None
else None, ),
"pnmsong": url_for("popn_pages.viewtopscores", musicid=-1) "pnmsong": (
if GameConstants.POPN_MUSIC in g.config.support url_for("popn_pages.viewtopscores", musicid=-1)
else None, if GameConstants.POPN_MUSIC in g.config.support
else None
),
}, },
) )

View File

@ -10,7 +10,6 @@ from bemani.data import Data, Config, Score, Attempt, Link, Song, UserID, Remote
class FrontendBase(ABC): class FrontendBase(ABC):
""" """
All subclasses should override this attribute with the string All subclasses should override this attribute with the string
the game series uses in the DB. the game series uses in the DB.

View File

@ -20,9 +20,9 @@ class EAmuseProtocol:
A wrapper object that encapsulates encoding/decoding the E-Amusement protocol by Konami. A wrapper object that encapsulates encoding/decoding the E-Amusement protocol by Konami.
""" """
SHARED_SECRET: Final[ SHARED_SECRET: Final[bytes] = (
bytes b"\x69\xD7\x46\x27\xD9\x85\xEE\x21\x87\x16\x15\x70\xD0\x8D\x93\xB1\x24\x55\x03\x5B\x6D\xF0\xD8\x20\x5D\xF5"
] = b"\x69\xD7\x46\x27\xD9\x85\xEE\x21\x87\x16\x15\x70\xD0\x8D\x93\xB1\x24\x55\x03\x5B\x6D\xF0\xD8\x20\x5D\xF5" )
XML: Final[int] = 1 XML: Final[int] = 1
BINARY: Final[int] = 2 BINARY: Final[int] = 2

View File

@ -71,8 +71,7 @@ class TestParallel(unittest.TestCase):
def test_class(self) -> None: def test_class(self) -> None:
class Base(ABC): class Base(ABC):
def fun(self, x: int) -> int: def fun(self, x: int) -> int: ...
...
class A(Base): class A(Base):
def fun(self, x: int) -> int: def fun(self, x: int) -> int:

View File

@ -11,9 +11,9 @@ import struct
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from pathlib import Path from pathlib import Path
from sqlalchemy.engine import CursorResult # type: ignore from sqlalchemy.engine import CursorResult # type: ignore
from sqlalchemy.orm import sessionmaker # type: ignore from sqlalchemy.orm import sessionmaker
from sqlalchemy.sql import text # type: ignore from sqlalchemy.sql import text
from sqlalchemy.exc import IntegrityError # type: ignore from sqlalchemy.exc import IntegrityError
from typing import Any, Callable, Dict, List, Optional, Tuple from typing import Any, Callable, Dict, List, Optional, Tuple
from bemani.common import ( from bemani.common import (
@ -1943,15 +1943,21 @@ class ImportPopn(ImportBase):
"artist": read_string(unpacked[config.artist_offset]), "artist": read_string(unpacked[config.artist_offset]),
"genre": read_string(unpacked[config.genre_offset]), "genre": read_string(unpacked[config.genre_offset]),
"comment": read_string(unpacked[config.comment_offset]), "comment": read_string(unpacked[config.comment_offset]),
"title_en": read_string(unpacked[config.english_title_offset]) "title_en": (
if config.english_title_offset is not None read_string(unpacked[config.english_title_offset])
else "", if config.english_title_offset is not None
"artist_en": read_string(unpacked[config.english_artist_offset]) else ""
if config.english_artist_offset is not None ),
else "", "artist_en": (
"long_genre": read_string(unpacked[config.extended_genre_offset]) read_string(unpacked[config.english_artist_offset])
if config.extended_genre_offset is not None if config.english_artist_offset is not None
else "", else ""
),
"long_genre": (
read_string(unpacked[config.extended_genre_offset])
if config.extended_genre_offset is not None
else ""
),
"folder": unpacked[config.folder_offset], "folder": unpacked[config.folder_offset],
"difficulty": { "difficulty": {
"standard": { "standard": {
@ -1967,24 +1973,28 @@ class ImportPopn(ImportBase):
}, },
"file": { "file": {
"standard": { "standard": {
"easy": file_handle(config, unpacked[config.easy_file_offset]) "easy": (
if valid_charts[0] file_handle(config, unpacked[config.easy_file_offset]) if valid_charts[0] else ""
else "", ),
"normal": file_handle(config, unpacked[config.normal_file_offset]) "normal": (
if valid_charts[1] file_handle(config, unpacked[config.normal_file_offset]) if valid_charts[1] else ""
else "", ),
"hyper": file_handle(config, unpacked[config.hyper_file_offset]) "hyper": (
if valid_charts[2] file_handle(config, unpacked[config.hyper_file_offset]) if valid_charts[2] else ""
else "", ),
"ex": file_handle(config, unpacked[config.ex_file_offset]) if valid_charts[3] else "", "ex": file_handle(config, unpacked[config.ex_file_offset]) if valid_charts[3] else "",
}, },
"battle": { "battle": {
"normal": file_handle(config, unpacked[config.battle_normal_file_offset]) "normal": (
if valid_charts[4] file_handle(config, unpacked[config.battle_normal_file_offset])
else "", if valid_charts[4]
"hyper": file_handle(config, unpacked[config.battle_hyper_file_offset]) else ""
if valid_charts[5] ),
else "", "hyper": (
file_handle(config, unpacked[config.battle_hyper_file_offset])
if valid_charts[5]
else ""
),
}, },
}, },
} }
@ -1998,7 +2008,11 @@ class ImportPopn(ImportBase):
# This is a removed song # This is a removed song
continue continue
if songinfo["title"] == "" and songinfo["artist"] == "" and songinfo["genre"] == "": if (
songinfo["title"] == ""
and songinfo["artist"] == ""
and songinfo["genre"] == ""
):
# This is a song the intern left in # This is a song the intern left in
continue continue