Skip to content

fix: transform xp to 0 if currently None for main pokemon#309

Closed
MrElektronz wants to merge 2 commits intoh0tp-ftw:mainfrom
MrElektronz:mrelektronz/battle-view-fix
Closed

fix: transform xp to 0 if currently None for main pokemon#309
MrElektronz wants to merge 2 commits intoh0tp-ftw:mainfrom
MrElektronz:mrelektronz/battle-view-fix

Conversation

@MrElektronz
Copy link

Issue posted on discord: https://discord.com/channels/1241773562629718148/1475088305392451656

After updating from the current version from ankiweb to the 1.52-E release I got the following issue after every reviewed card and when trying to open the "Ankimon Window".
The issue was that my main-pokemon had an "xp" attribute of None.
This got fixed in the save_main_pokemon function. If the main pokemon has None xp this gets overwritten to 0 now.

I also added some nice touches, such as adding the return value of update_main_pokemon. If this is not desired in this project I can remove it, but it adds more readability and thus maintainability imo.

@gemini-code-assist
Copy link

Summary of Changes

Hello @MrElektronz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug where the main Pokémon's experience points (xp) could be None, leading to errors when interacting with the Ankimon system. The changes ensure that xp is consistently initialized and handled as an integer, specifically 0, preventing runtime exceptions and improving the robustness of the Pokémon data management. This resolves issues encountered after updating the application, particularly for users with existing data that might have None xp values.

Highlights

  • XP Attribute Initialization: The default xp value in DEFAULT_POKEMON_OBJECT has been changed from None to 0 to prevent issues with uninitialized experience points.
  • Robust XP Handling in PokemonObject: The PokemonObject's constructor (__init__) now explicitly handles cases where xp might be None, ensuring it defaults to 0 to maintain data integrity.
  • Legacy Data Migration for XP: A fix has been implemented in the save_main_pokemon function to convert any existing None xp values to 0 before saving, addressing issues from older data formats.
  • Improved Type Hinting: The update_main_pokemon function now includes a return type hint, enhancing code readability and maintainability.
Changelog
  • src/Ankimon/functions/update_main_pokemon.py
    • Updated the DEFAULT_POKEMON_OBJECT dictionary to set the initial xp value to 0 instead of None.
    • Added a return type annotation -> tuple[PokemonObject, bool] to the update_main_pokemon function signature.
    • Implemented a conditional assignment within save_main_pokemon to convert main_pokemon.xp from None to 0 if it is None.
  • src/Ankimon/pyobj/pokemon_obj.py
    • Included xp as a parameter in the PokemonObject's __init__ method, assigning it to self.xp.
    • Modified the xp assignment within PokemonObject's __init__ to ensure self.xp defaults to 0 if the provided xp argument is None.
Activity
  • The author, MrElektronz, identified an issue where the main Pokémon's xp attribute was None after updating the application, leading to errors.
  • An issue was posted on Discord to report the problem.
  • MrElektronz created this pull request to fix the identified None xp issue, including a legacy fix for existing data and adding return type hints for clarity.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request effectively addresses the issue where the xp attribute of the main Pokémon could be None, leading to errors during gameplay and when opening the Ankimon window. The changes ensure that xp defaults to 0 in the configuration, during object initialization, and as a safeguard when saving. The addition of type hints to update_main_pokemon improves code clarity and maintainability. I have identified one minor redundancy in the PokemonObject constructor.

@abr-Projects
Copy link

this might be a duplicate of #300 ?

@MrElektronz
Copy link
Author

this might be a duplicate of #300 ?

Yep good catch, the other PR should also fix the underlying issue fixed here :D

@MrElektronz MrElektronz deleted the mrelektronz/battle-view-fix branch February 23, 2026 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants