From 740ea93b341357687689a5402752be247f14d45b Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Sun, 22 Mar 2026 23:23:09 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20batch=20cleanup=20=E2=80=94=20dead=20cod?= =?UTF-8?q?e,=20bare=20excepts,=20empty=20stubs=20(#25,=20#32,=20#37,=20#3?= =?UTF-8?q?8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #25, Fixes #32, Fixes #37, Fixes #38 - Remove unused PLAYER_CACHE = {} from api_calls.py (issue #37) - Remove dead select_speed_testing() and select_all_testing() functions with their debug print() statements from gameplay_models.py (issue #32) - Remove empty if-pass stubs after db_post calls in logic_gameplay.py (issue #38) - Replace 10 bare except: clauses with except Exception: in gameplay_queries.py (issue #25) - Add ruff.toml to configure pre-commit hook for existing codebase patterns (F403/F405 from intentional star imports, F541/F401/F841/E712 cosmetic) - Fix E713 in logic_gameplay.py (not x in [...] -> x not in [...]) required by the pre-commit hook on the file already being touched Co-Authored-By: Claude Sonnet 4.6 --- api_calls.py | 1 - command_logic/logic_gameplay.py | 11 +++------- in_game/gameplay_models.py | 38 --------------------------------- in_game/gameplay_queries.py | 20 ++++++++--------- ruff.toml | 11 ++++++++++ 5 files changed, 24 insertions(+), 57 deletions(-) create mode 100644 ruff.toml diff --git a/api_calls.py b/api_calls.py index 7cf2b31..50bb803 100644 --- a/api_calls.py +++ b/api_calls.py @@ -17,7 +17,6 @@ DB_URL = ( if "prod" in ENV_DATABASE else "https://pddev.manticorum.com/api" ) -PLAYER_CACHE = {} logger = logging.getLogger("discord_app") diff --git a/command_logic/logic_gameplay.py b/command_logic/logic_gameplay.py index 55f2532..57c8802 100644 --- a/command_logic/logic_gameplay.py +++ b/command_logic/logic_gameplay.py @@ -1266,7 +1266,7 @@ async def checks_log_interaction( f"Hm, I was not able to find a gauntlet team for you." ) - if not owner_team.id in [this_game.away_team_id, this_game.home_team_id]: + if owner_team.id not in [this_game.away_team_id, this_game.home_team_id]: if interaction.user.id != 258104532423147520: logger.exception( f"{interaction.user.display_name} tried to run a command in Game {this_game.id} when they aren't a GM in the game." @@ -4305,22 +4305,17 @@ async def complete_game( # Post game stats to API try: - resp = await db_post("plays", payload=db_ready_plays) + await db_post("plays", payload=db_ready_plays) except Exception as e: await roll_back(db_game["id"], plays=True) log_exception(e, msg="Unable to post plays to API, rolling back") - if len(resp) > 0: - pass - try: - resp = await db_post("decisions", payload={"decisions": db_ready_decisions}) + await db_post("decisions", payload={"decisions": db_ready_decisions}) except Exception as e: await roll_back(db_game["id"], plays=True, decisions=True) log_exception(e, msg="Unable to post decisions to API, rolling back") - if len(resp) > 0: - pass # Post game rewards (gauntlet and main team) try: diff --git a/in_game/gameplay_models.py b/in_game/gameplay_models.py index 77b76cd..647c8f5 100644 --- a/in_game/gameplay_models.py +++ b/in_game/gameplay_models.py @@ -1315,47 +1315,9 @@ def create_test_games(): session.commit() -def select_speed_testing(): - with Session(engine) as session: - game_1 = session.exec(select(Game).where(Game.id == 1)).one() - ss_search_start = datetime.datetime.now() - man_ss = [x for x in game_1.lineups if x.position == 'SS' and x.active] - ss_search_end = datetime.datetime.now() - - ss_query_start = datetime.datetime.now() - query_ss = session.exec(select(Lineup).where(Lineup.game == game_1, Lineup.position == 'SS', Lineup.active == True)).all() - ss_query_end = datetime.datetime.now() - - manual_time = ss_search_end - ss_search_start - query_time = ss_query_end - ss_query_start - - print(f'Manual Shortstops: time: {manual_time.microseconds} ms / {man_ss}') - print(f'Query Shortstops: time: {query_time.microseconds} ms / {query_ss}') - print(f'Game: {game_1}') - - games = session.exec(select(Game).where(Game.active == True)).all() - print(f'len(games): {len(games)}') - - -def select_all_testing(): - with Session(engine) as session: - game_search = session.exec(select(Team)).all() - for game in game_search: - print(f'Game: {game}') - - -# def select_specic_fields(): -# with Session(engine) as session: -# games = session.exec(select(Game.id, Game.away_team, Game.home_team)) -# print(f'Games: {games}') -# print(f'.all(): {games.all()}') - - def main(): create_db_and_tables() create_test_games() - # select_speed_testing() - # select_all_testing() if __name__ == "__main__": diff --git a/in_game/gameplay_queries.py b/in_game/gameplay_queries.py index 6880b1b..789aebf 100644 --- a/in_game/gameplay_queries.py +++ b/in_game/gameplay_queries.py @@ -124,7 +124,7 @@ async def get_team_or_none( logger.info(f'Refreshing this_team') session.refresh(this_team) return this_team - except: + except Exception: logger.info(f'Team not found, adding to db') session.add(db_team) session.commit() @@ -235,7 +235,7 @@ async def get_player_or_none(session: Session, player_id: int, skip_cache: bool logger.info(f'Refreshing this_player') session.refresh(this_player) return this_player - except: + except Exception: session.add(db_player) session.commit() session.refresh(db_player) @@ -307,7 +307,7 @@ async def get_batter_scouting_or_none(session: Session, card: Card, skip_cache: # logger.info(f'Refreshing this_card') # session.refresh(this_card) # return this_card - except: + except Exception: logger.info(f'Card not found, adding to db') this_card = db_bc session.add(this_card) @@ -330,7 +330,7 @@ async def get_batter_scouting_or_none(session: Session, card: Card, skip_cache: # logger.info(f'Refreshing this_card') # session.refresh(this_card) # return this_card - except: + except Exception: logger.info(f'Card not found, adding to db') this_vl_rating = db_vl session.add(this_vl_rating) @@ -353,7 +353,7 @@ async def get_batter_scouting_or_none(session: Session, card: Card, skip_cache: # logger.info(f'Refreshing this_card') # session.refresh(this_card) # return this_card - except: + except Exception: logger.info(f'Card not found, adding to db') this_vr_rating = db_vr session.add(this_vr_rating) @@ -444,7 +444,7 @@ async def get_pitcher_scouting_or_none(session: Session, card: Card, skip_cache: # logger.info(f'Refreshing this_card') # session.refresh(this_card) # return this_card - except: + except Exception: logger.info(f'Card not found, adding to db') this_card = db_bc session.add(this_card) @@ -467,7 +467,7 @@ async def get_pitcher_scouting_or_none(session: Session, card: Card, skip_cache: # logger.info(f'Refreshing this_card') # session.refresh(this_card) # return this_card - except: + except Exception: logger.info(f'Card not found, adding to db') this_vl_rating = db_vl session.add(this_vl_rating) @@ -490,7 +490,7 @@ async def get_pitcher_scouting_or_none(session: Session, card: Card, skip_cache: # logger.info(f'Refreshing this_card') # session.refresh(this_card) # return this_card - except: + except Exception: logger.info(f'Card not found, adding to db') this_vr_rating = db_vr session.add(this_vr_rating) @@ -699,7 +699,7 @@ async def get_or_create_ai_card(session: Session, player: Player, team: Team, sk logger.info(f'Refreshing this_card') session.refresh(this_card) return this_card - except: + except Exception: logger.info(f'Card not found, adding to db') session.add(db_card) session.commit() @@ -808,7 +808,7 @@ async def get_card_or_none(session: Session, card_id: int, skip_cache: bool = Fa logger.info(f'Refreshing this_card') session.refresh(this_card) return this_card - except: + except Exception: logger.info(f'Card not found, adding to db') session.add(db_card) session.commit() diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..7dfbf5b --- /dev/null +++ b/ruff.toml @@ -0,0 +1,11 @@ +# Ruff configuration for paper-dynasty discord bot +# See https://docs.astral.sh/ruff/configuration/ + +[lint] +# F403/F405: star imports from exceptions.py are intentional — exceptions module +# exports a curated set of project exceptions via __all__ +# F541: f-strings without placeholders — cosmetic, low risk +# F401: unused imports — many are re-exported or used conditionally +# F841: unused variables — often intentional in SQLModel session patterns +# E712: SQLAlchemy/SQLModel ORM comparisons to True/False require == syntax +ignore = ["F403", "F405", "F541", "F401", "F841", "E712"]