Skip to content

feat: fallback front_female sprite to front_default for female-only p… - #1573

Merged
FallenDeity merged 2 commits into
PokeAPI:masterfrom
programgames:271-female-sprites
Aug 29, 2026
Merged

feat: fallback front_female sprite to front_default for female-only p…#1573
FallenDeity merged 2 commits into
PokeAPI:masterfrom
programgames:271-female-sprites

Conversation

@programgames

@programgames programgames commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Changes description

A simple solution for the #271 .
If the request if a simple GET for the pokemon, we select the specie and check if the gender rate is only female.
In this case we copy the valuer from default to female sprites with this mapping :

_FEMALE_FALLBACKS = {
    "front_female": "front_default",
    "back_female": "back_default",
    "front_shiny_female": "front_shiny",
    "back_shiny_female": "back_shiny",
}

PS : I would like to know if Pokemon.objects.all().select_related("pokemon_species") could be a performance problem on the server, Should I test performance before and after this change to compare ?

AI coding assistance disclosure

I used AI to improve my indentation after my manual changes, make a test and understand/fix from PR reviews.
I also undestand what the AI did to my code.

Contributor check list

  • I have written a description of the contribution and explained its motivation.
  • I have written tests for my code changes (if applicable).
  • I have read and understood the AI Assisted Contribution guidelines.
  • I will own this change in production, and I am prepared to fix any bugs caused by my code change.

Comment thread pokemon_v2/api.py Outdated
serializer_class = PokemonDetailSerializer
list_serializer_class = PokemonSummarySerializer

def get_queryset(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Very interesting implementation. Can I ask what's the purpose of this function? It's for having ready at hand some data later on in the serializer.py part?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi, @programgames caould you address the above question?

Comment thread pokemon_v2/serializers.py Outdated
"back_shiny_female": "back_shiny",
}

def _fill_female_sprites(self, node):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm strongly of the opinion that the data should just be shared with PokeAPI and consumers should handle this themselves.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Among the years we always pulled data from veekun which in turn got it from decompilations. The data was sometimes pretty cryptic to use. I can mention the use of rare Unicode characters, having braces in strings that acted as templates, having hidden characters and so on. In the beginning we were reluctant to change these pieces of data turning to the users to implement custom strategies.

Eventually we cleaned the garbage that we were serving and everyone was happier. Maybe valuing user-friendliness over strict data rules was the key to it.

That said I'm in favour of these kind of changes. If a pokemon has a 100% female rate then the female_sprite can be inferred to be the same as the default_sprite. In this case default_sprite and female_sprite coincide. By having the female_sprite filled in (by this custom logic or any other method) is ok with me.

@programgames

Copy link
Copy Markdown
Contributor Author

Free feel to ping me if changes are needed.

Comment thread pokemon_v2/serializers.py Outdated
Comment on lines +4268 to +4269
sprites = sprites_object.sprites
if obj.pokemon_species.gender_rate == 8:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@programgames would you be able to update your code and fix the conflict in this file? Recently @FallenDeity heavily rewrote it and I wasn't able to fix the conflict by myself.

…e-only pokemon

For pokemon whose species has gender_rate=8 (exclusively female), fill the
null female sprite keys with their default counterparts across all sprite
sections.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Comment thread pokemon_v2/serializers.py Outdated
Comment thread pokemon_v2/serializers.py Outdated
Comment thread pokemon_v2/serializers.py Outdated
Comment thread pokemon_v2/serializers.py Outdated
refactor: simplify female sprite fallback per review

The sprites model field is a JSONField, so it is always decoded to a
python dict on read: drop the string/json.loads/json.dumps branch which
would have returned an escaped JSON string in the response.

Simplify get_pokemon_sprites to a positive guard and narrow its return
type to dict[str, Any]. In _fill_female_sprites, type the parameter as
dict[str, Any] and move the isinstance check into the recursion loop
instead of guarding at the function entry, which also removes a cast.

Align the test fixture with data/v2/build.py: it double-encoded the
sprites dict with json.dumps before storing it in the JSONField.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@
@FallenDeity

Copy link
Copy Markdown
Contributor

everything looks good to me but please add the ai usage disclaimer/disclosure in your pr desc we have a template here: https://github.com/PokeAPI/pokeapi/blob/master/.github/pull_request_template.md

@FallenDeity
FallenDeity merged commit 3a588cf into PokeAPI:master Aug 29, 2026
22 checks passed
@pokeapi-machine-user

Copy link
Copy Markdown

A PokeAPI/api-data refresh has started. In ~45 minutes the staging branch of PokeAPI/api-data will be pushed with the new generated data.

The staging branch will be deployed in our staging environment and the entire API will be ready to review.

A Pull Request (master<-staging) will be also created at PokeAPI/api-data and assigned to the PokeAPI Core team to be reviewed. If approved and merged new data will soon be available worldwide at pokeapi.co.

@pokeapi-machine-user

Copy link
Copy Markdown

The updater script has finished its job and has now opened a Pull Request towards PokeAPI/api-data with the updated data.

The Pull Request can be seen deployed in our staging environment when CircleCI deploy will be finished (check the start time of the last build).

FallenDeity pushed a commit to PokeAPI/api-data that referenced this pull request Aug 29, 2026
@FallenDeity

Copy link
Copy Markdown
Contributor
image

its live now thx @programgames

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.

5 participants