From f63247b605b1a841ef58b1103bb7165efa31e652 Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Sat, 30 Mar 2024 02:07:21 +0000 Subject: [PATCH] Fix some new typing errors (a bunch of ignores can be removed!), black errors. --- bemani/backend/jubeat/base.py | 2 +- bemani/backend/jubeat/festo.py | 12 ++++-- bemani/data/api/music.py | 40 ++++++++++--------- bemani/data/config.py | 2 +- bemani/data/data.py | 14 +++---- bemani/data/mysql/api.py | 4 +- bemani/data/mysql/base.py | 10 ++--- bemani/data/mysql/game.py | 6 +-- bemani/data/mysql/lobby.py | 6 +-- bemani/data/mysql/machine.py | 6 +-- bemani/data/mysql/music.py | 8 ++-- bemani/data/mysql/network.py | 6 +-- bemani/data/mysql/user.py | 8 ++-- bemani/format/afp/swf.py | 14 ++++--- bemani/frontend/admin/admin.py | 20 +++++----- bemani/frontend/base.py | 1 - bemani/protocol/protocol.py | 6 +-- bemani/tests/test_Parallel.py | 3 +- bemani/utils/read.py | 70 ++++++++++++++++++++-------------- 19 files changed, 131 insertions(+), 107 deletions(-) diff --git a/bemani/backend/jubeat/base.py b/bemani/backend/jubeat/base.py index 1f17cb4..5b46c35 100644 --- a/bemani/backend/jubeat/base.py +++ b/bemani/backend/jubeat/base.py @@ -177,7 +177,7 @@ class JubeatBase(CoreHandler, CardManagerHandler, PASELIHandler, Base): else: # We will want to fetch the remaining scores that were in our # cache. - scores = self.cache.get(cache_key) # type: ignore + scores = self.cache.get(cache_key) if len(scores) < 50: # We simply return the whole amount for this, and cache nothing. diff --git a/bemani/backend/jubeat/festo.py b/bemani/backend/jubeat/festo.py index ed76e38..3850a3b 100644 --- a/bemani/backend/jubeat/festo.py +++ b/bemani/backend/jubeat/festo.py @@ -530,10 +530,14 @@ class JubeatFesto( ], [ ( - 80000034 - if dataver < 2020062900 - else ( - 30000108 if dataver < 2020091300 else (40000107 if dataver < 2021020100 else 30000004) + ( + 80000034 + if dataver < 2020062900 + else ( + 30000108 + if dataver < 2020091300 + else (40000107 if dataver < 2021020100 else 30000004) + ) ), 0, ), diff --git a/bemani/data/api/music.py b/bemani/data/api/music.py index 05de65a..ba3e4ee 100644 --- a/bemani/data/api/music.py +++ b/bemani/data/api/music.py @@ -335,12 +335,12 @@ class GlobalMusicData(BaseGlobalData): { "rank": self.__max(oldscore.data["rank"], newscore.data["rank"]), "halo": self.__max(oldscore.data["halo"], newscore.data["halo"]), - "ghost": oldscore.data.get("ghost") - if oldscore.points > newscore.points - else newscore.data.get("ghost"), - "trace": oldscore.data.get("trace") - if oldscore.points > newscore.points - else newscore.data.get("trace"), + "ghost": ( + oldscore.data.get("ghost") if oldscore.points > newscore.points else newscore.data.get("ghost") + ), + "trace": ( + oldscore.data.get("trace") if oldscore.points > newscore.points else newscore.data.get("trace") + ), "combo": self.__max(oldscore.data["combo"], newscore.data["combo"]), }, ) @@ -360,19 +360,23 @@ class GlobalMusicData(BaseGlobalData): oldscore.plays + newscore.plays, { "clear_status": self.__max(oldscore.data["clear_status"], newscore.data["clear_status"]), - "ghost": oldscore.data.get("ghost") - if oldscore.points > newscore.points - else newscore.data.get("ghost"), + "ghost": ( + oldscore.data.get("ghost") if oldscore.points > newscore.points else newscore.data.get("ghost") + ), "miss_count": self.__min( oldscore.data.get_int("miss_count", -1), newscore.data.get_int("miss_count", -1), ), - "pgreats": oldscore.data.get_int("pgreats", -1) - if oldscore.points > newscore.points - else newscore.data.get_int("pgreats", -1), - "greats": oldscore.data.get_int("greats", -1) - if oldscore.points > newscore.points - else newscore.data.get_int("greats", -1), + "pgreats": ( + oldscore.data.get_int("pgreats", -1) + if oldscore.points > newscore.points + else newscore.data.get_int("pgreats", -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.plays + newscore.plays, { - "ghost": oldscore.data.get("ghost") - if oldscore.points > newscore.points - else newscore.data.get("ghost"), + "ghost": ( + oldscore.data.get("ghost") if oldscore.points > newscore.points else newscore.data.get("ghost") + ), "combo": self.__max(oldscore.data["combo"], newscore.data["combo"]), "medal": self.__max(oldscore.data["medal"], newscore.data["medal"]), # Conditionally include this if we have any info for it. diff --git a/bemani/data/config.py b/bemani/data/config.py index 92f8ae2..e066c08 100644 --- a/bemani/data/config.py +++ b/bemani/data/config.py @@ -1,6 +1,6 @@ import copy import os -from sqlalchemy.engine import Engine # type: ignore +from sqlalchemy.engine import Engine from typing import Any, Dict, Optional, Set from bemani.common import GameConstants, RegionConstants diff --git a/bemani/data/data.py b/bemani/data/data.py index 3df7086..9401989 100644 --- a/bemani/data/data.py +++ b/bemani/data/data.py @@ -2,13 +2,13 @@ import os import alembic.config from alembic.migration import MigrationContext -from alembic.autogenerate import compare_metadata # type: ignore -from sqlalchemy import create_engine # type: ignore -from sqlalchemy.orm import scoped_session # type: ignore +from alembic.autogenerate import compare_metadata +from sqlalchemy import create_engine +from sqlalchemy.orm import scoped_session from sqlalchemy.orm import sessionmaker -from sqlalchemy.engine import Engine # type: ignore -from sqlalchemy.sql import text # type: ignore -from sqlalchemy.exc import ProgrammingError # type: ignore +from sqlalchemy.engine import Engine +from sqlalchemy.sql import text +from sqlalchemy.exc import ProgrammingError from bemani.data.api.user import GlobalUserData from bemani.data.api.game import GlobalGameData @@ -153,7 +153,7 @@ class Data: ] alembicArgs.extend(args) os.chdir(base_dir) - alembic.config.main(argv=alembicArgs) # type: ignore + alembic.config.main(argv=alembicArgs) def create(self) -> None: """ diff --git a/bemani/data/mysql/api.py b/bemani/data/mysql/api.py index 7444b0c..263ae81 100644 --- a/bemani/data/mysql/api.py +++ b/bemani/data/mysql/api.py @@ -1,6 +1,6 @@ import uuid -from sqlalchemy import Table, Column # type: ignore -from sqlalchemy.types import String, Integer # type: ignore +from sqlalchemy import Table, Column +from sqlalchemy.types import String, Integer from typing import Any, Dict, List, Optional from bemani.common import Time diff --git a/bemani/data/mysql/base.py b/bemani/data/mysql/base.py index 1c71395..015758c 100644 --- a/bemani/data/mysql/base.py +++ b/bemani/data/mysql/base.py @@ -6,11 +6,11 @@ from typing_extensions import Final from bemani.common import Time from bemani.data.config import Config -from sqlalchemy.engine.base import Connection # type: ignore from sqlalchemy.engine import CursorResult # type: ignore -from sqlalchemy.sql import text # type: ignore -from sqlalchemy.types import String, Integer # type: ignore -from sqlalchemy import Table, Column, MetaData # type: ignore +from sqlalchemy.orm import scoped_session +from sqlalchemy.sql import text +from sqlalchemy.types import String, Integer +from sqlalchemy import Table, Column, MetaData metadata = MetaData() @@ -40,7 +40,7 @@ class _BytesEncoder(json.JSONEncoder): class BaseData: 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. diff --git a/bemani/data/mysql/game.py b/bemani/data/mysql/game.py index 2b92082..c9e5cd6 100644 --- a/bemani/data/mysql/game.py +++ b/bemani/data/mysql/game.py @@ -1,6 +1,6 @@ -from sqlalchemy import Table, Column, UniqueConstraint # type: ignore -from sqlalchemy.types import String, Integer, JSON # type: ignore -from sqlalchemy.dialects.mysql import BIGINT as BigInteger # type: ignore +from sqlalchemy import Table, Column, UniqueConstraint +from sqlalchemy.types import String, Integer, JSON +from sqlalchemy.dialects.mysql import BIGINT as BigInteger from typing import Any, Dict, List, Optional from bemani.common import GameConstants, ValidatedDict, Time diff --git a/bemani/data/mysql/lobby.py b/bemani/data/mysql/lobby.py index 0657c83..31698fe 100644 --- a/bemani/data/mysql/lobby.py +++ b/bemani/data/mysql/lobby.py @@ -1,8 +1,8 @@ import copy -from sqlalchemy import Table, Column, UniqueConstraint # type: ignore -from sqlalchemy.types import String, Integer, JSON # type: ignore -from sqlalchemy.dialects.mysql import BIGINT as BigInteger # type: ignore +from sqlalchemy import Table, Column, UniqueConstraint +from sqlalchemy.types import String, Integer, JSON +from sqlalchemy.dialects.mysql import BIGINT as BigInteger from typing import Optional, Dict, List, Tuple, Any from bemani.common import GameConstants, ValidatedDict, Time diff --git a/bemani/data/mysql/machine.py b/bemani/data/mysql/machine.py index 0abf18e..95430a5 100644 --- a/bemani/data/mysql/machine.py +++ b/bemani/data/mysql/machine.py @@ -1,6 +1,6 @@ -from sqlalchemy import Table, Column, UniqueConstraint # type: ignore -from sqlalchemy.types import String, Integer, JSON # type: ignore -from sqlalchemy.dialects.mysql import BIGINT as BigInteger # type: ignore +from sqlalchemy import Table, Column, UniqueConstraint +from sqlalchemy.types import String, Integer, JSON +from sqlalchemy.dialects.mysql import BIGINT as BigInteger from typing import Optional, Dict, List, Tuple, Any from typing_extensions import Final diff --git a/bemani/data/mysql/music.py b/bemani/data/mysql/music.py index 7ecda29..35d7767 100644 --- a/bemani/data/mysql/music.py +++ b/bemani/data/mysql/music.py @@ -1,7 +1,7 @@ -from sqlalchemy import Table, Column, UniqueConstraint # type: ignore -from sqlalchemy.exc import IntegrityError # type: ignore -from sqlalchemy.types import String, Integer, JSON # type: ignore -from sqlalchemy.dialects.mysql import BIGINT as BigInteger # type: ignore +from sqlalchemy import Table, Column, UniqueConstraint +from sqlalchemy.exc import IntegrityError +from sqlalchemy.types import String, Integer, JSON +from sqlalchemy.dialects.mysql import BIGINT as BigInteger from typing import Optional, Dict, List, Tuple, Any from bemani.common import GameConstants, Time diff --git a/bemani/data/mysql/network.py b/bemani/data/mysql/network.py index 45394b9..8c4c5aa 100644 --- a/bemani/data/mysql/network.py +++ b/bemani/data/mysql/network.py @@ -1,6 +1,6 @@ -from sqlalchemy import Table, Column, UniqueConstraint # type: ignore -from sqlalchemy.types import String, Integer, Text, JSON # type: ignore -from sqlalchemy.dialects.mysql import BIGINT as BigInteger # type: ignore +from sqlalchemy import Table, Column, UniqueConstraint +from sqlalchemy.types import String, Integer, Text, JSON +from sqlalchemy.dialects.mysql import BIGINT as BigInteger from typing import Optional, Dict, List, Tuple, Any from bemani.common import GameConstants, Time diff --git a/bemani/data/mysql/user.py b/bemani/data/mysql/user.py index 5ab8304..c48089a 100644 --- a/bemani/data/mysql/user.py +++ b/bemani/data/mysql/user.py @@ -1,8 +1,8 @@ import random -from sqlalchemy import Table, Column, UniqueConstraint # type: ignore -from sqlalchemy.types import String, Integer, JSON # type: ignore -from sqlalchemy.dialects.mysql import BIGINT as BigInteger # type: ignore -from sqlalchemy.exc import IntegrityError # type: ignore +from sqlalchemy import Table, Column, UniqueConstraint +from sqlalchemy.types import String, Integer, JSON +from sqlalchemy.dialects.mysql import BIGINT as BigInteger +from sqlalchemy.exc import IntegrityError from typing import Optional, Dict, List, Tuple, Any from typing_extensions import Final from passlib.hash import pbkdf2_sha512 # type: ignore diff --git a/bemani/format/afp/swf.py b/bemani/format/afp/swf.py index 513df90..a72dc06 100644 --- a/bemani/format/afp/swf.py +++ b/bemani/format/afp/swf.py @@ -377,12 +377,14 @@ class AP2PlaceObjectTag(Tag): "blend": self.blend, "update": self.update, "transform": self.transform.as_dict(*args, **kwargs) if self.transform is not None else None, - "rotation_origin": self.rotation_origin.as_dict(*args, **kwargs) - if self.rotation_origin is not None - else None, - "projection": "none" - if self.projection == self.PROJECTION_NONE - else ("affine" if self.projection == self.PROJECTION_AFFINE else "perspective"), + "rotation_origin": ( + self.rotation_origin.as_dict(*args, **kwargs) if self.rotation_origin is not None else None + ), + "projection": ( + "none" + 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, "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, diff --git a/bemani/frontend/admin/admin.py b/bemani/frontend/admin/admin.py index ac5f6b0..afcdfd5 100644 --- a/bemani/frontend/admin/admin.py +++ b/bemani/frontend/admin/admin.py @@ -175,15 +175,17 @@ def viewevents() -> Response: "refresh": url_for("admin_pages.listevents", since=-1), "backfill": url_for("admin_pages.backfillevents", until=-1), "viewuser": url_for("admin_pages.viewuser", userid=-1), - "jubeatsong": url_for("jubeat_pages.viewtopscores", musicid=-1) - if GameConstants.JUBEAT in g.config.support - else None, - "iidxsong": url_for("iidx_pages.viewtopscores", musicid=-1) - if GameConstants.IIDX in g.config.support - else None, - "pnmsong": url_for("popn_pages.viewtopscores", musicid=-1) - if GameConstants.POPN_MUSIC in g.config.support - else None, + "jubeatsong": ( + url_for("jubeat_pages.viewtopscores", musicid=-1) if GameConstants.JUBEAT in g.config.support else None + ), + "iidxsong": ( + url_for("iidx_pages.viewtopscores", musicid=-1) if GameConstants.IIDX in g.config.support else None + ), + "pnmsong": ( + url_for("popn_pages.viewtopscores", musicid=-1) + if GameConstants.POPN_MUSIC in g.config.support + else None + ), }, ) diff --git a/bemani/frontend/base.py b/bemani/frontend/base.py index 485a4c2..c2a9e7c 100644 --- a/bemani/frontend/base.py +++ b/bemani/frontend/base.py @@ -10,7 +10,6 @@ from bemani.data import Data, Config, Score, Attempt, Link, Song, UserID, Remote class FrontendBase(ABC): - """ All subclasses should override this attribute with the string the game series uses in the DB. diff --git a/bemani/protocol/protocol.py b/bemani/protocol/protocol.py index 3c93adc..8d6ec10 100644 --- a/bemani/protocol/protocol.py +++ b/bemani/protocol/protocol.py @@ -20,9 +20,9 @@ class EAmuseProtocol: A wrapper object that encapsulates encoding/decoding the E-Amusement protocol by Konami. """ - SHARED_SECRET: Final[ - 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" + SHARED_SECRET: Final[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" + ) XML: Final[int] = 1 BINARY: Final[int] = 2 diff --git a/bemani/tests/test_Parallel.py b/bemani/tests/test_Parallel.py index 19c8d84..80db784 100644 --- a/bemani/tests/test_Parallel.py +++ b/bemani/tests/test_Parallel.py @@ -71,8 +71,7 @@ class TestParallel(unittest.TestCase): def test_class(self) -> None: class Base(ABC): - def fun(self, x: int) -> int: - ... + def fun(self, x: int) -> int: ... class A(Base): def fun(self, x: int) -> int: diff --git a/bemani/utils/read.py b/bemani/utils/read.py index 6ba1f1c..4baa47f 100644 --- a/bemani/utils/read.py +++ b/bemani/utils/read.py @@ -11,9 +11,9 @@ import struct import xml.etree.ElementTree as ET from pathlib import Path from sqlalchemy.engine import CursorResult # type: ignore -from sqlalchemy.orm import sessionmaker # type: ignore -from sqlalchemy.sql import text # type: ignore -from sqlalchemy.exc import IntegrityError # type: ignore +from sqlalchemy.orm import sessionmaker +from sqlalchemy.sql import text +from sqlalchemy.exc import IntegrityError from typing import Any, Callable, Dict, List, Optional, Tuple from bemani.common import ( @@ -1943,15 +1943,21 @@ class ImportPopn(ImportBase): "artist": read_string(unpacked[config.artist_offset]), "genre": read_string(unpacked[config.genre_offset]), "comment": read_string(unpacked[config.comment_offset]), - "title_en": read_string(unpacked[config.english_title_offset]) - if config.english_title_offset is not None - else "", - "artist_en": read_string(unpacked[config.english_artist_offset]) - if config.english_artist_offset is not None - else "", - "long_genre": read_string(unpacked[config.extended_genre_offset]) - if config.extended_genre_offset is not None - else "", + "title_en": ( + read_string(unpacked[config.english_title_offset]) + if config.english_title_offset is not None + else "" + ), + "artist_en": ( + read_string(unpacked[config.english_artist_offset]) + if config.english_artist_offset is not None + else "" + ), + "long_genre": ( + read_string(unpacked[config.extended_genre_offset]) + if config.extended_genre_offset is not None + else "" + ), "folder": unpacked[config.folder_offset], "difficulty": { "standard": { @@ -1967,24 +1973,28 @@ class ImportPopn(ImportBase): }, "file": { "standard": { - "easy": file_handle(config, unpacked[config.easy_file_offset]) - if valid_charts[0] - else "", - "normal": file_handle(config, unpacked[config.normal_file_offset]) - if valid_charts[1] - else "", - "hyper": file_handle(config, unpacked[config.hyper_file_offset]) - if valid_charts[2] - else "", + "easy": ( + file_handle(config, unpacked[config.easy_file_offset]) if valid_charts[0] else "" + ), + "normal": ( + file_handle(config, unpacked[config.normal_file_offset]) if valid_charts[1] else "" + ), + "hyper": ( + file_handle(config, unpacked[config.hyper_file_offset]) if valid_charts[2] else "" + ), "ex": file_handle(config, unpacked[config.ex_file_offset]) if valid_charts[3] else "", }, "battle": { - "normal": file_handle(config, unpacked[config.battle_normal_file_offset]) - if valid_charts[4] - else "", - "hyper": file_handle(config, unpacked[config.battle_hyper_file_offset]) - if valid_charts[5] - else "", + "normal": ( + file_handle(config, unpacked[config.battle_normal_file_offset]) + if valid_charts[4] + 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 continue - if songinfo["title"] == "DUMMY" and songinfo["artist"] == "DUMMY" and songinfo["genre"] == "DUMMY": + if ( + songinfo["title"] == "DUMMY" + and songinfo["artist"] == "DUMMY" + and songinfo["genre"] == "DUMMY" + ): # This is a song the intern left in continue