Skip to content

Feat/type checker - #1637

Open
FallenDeity wants to merge 13 commits into
PokeAPI:masterfrom
FallenDeity:feat/type-checker
Open

Feat/type checker#1637
FallenDeity wants to merge 13 commits into
PokeAPI:masterfrom
FallenDeity:feat/type-checker

Conversation

@FallenDeity

@FallenDeity FallenDeity commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Change description

I have written a detailed write up of the changes and decisions made for this pr in the gist u can find here and supporting details, please do give it a read summarizes all the changes nicely
https://gist.github.com/FallenDeity/aa36487a214ea4c40809949a6ccffe7b

here is a tldr for a quick overview

TLDR

This PR introduces critical performance optimizations, type safety, and linting standards to the codebase:

image
  • ruff lint all files and type out the django api surface with no errors reported, build and test py files left for future todo to limit scope of typing

Given there is some logical changes i would encourage checking it out locally perhaps running it too for better reviewing, I have tested the pr extensively and there shouldnt be any issues but feel free to request changes, the test and build process havent been modified only logical changes are to serializer.py and tests are running fine so this dosent introduce any regressions

AI coding assistance disclosure

Used some AI for analysis of serializers, some more exploration about django serializers and scripting/visualization to facilitate testing and diff across dumps

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.

@Naramsim Naramsim left a comment

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 Fallen! Thanks for the big and important PR! I reviewed some files and asked some questions.

Note: I didn't review nor take a glimpse at openapi.yml, tests.py, serializers.py, models.py, api.py yet.

Comment thread .github/workflows/code-quality.yml Outdated
Comment thread .github/workflows/code-quality.yml
Comment thread .github/workflows/database.yml
Comment thread config/__init__.py
Comment thread config/asgi.py
Comment thread config/settings.py Outdated
Comment thread config/settings.py Outdated
Comment thread config/settings.py Outdated
Comment thread data/v2/build.py Outdated
Comment thread pokemon_v2/migrations/0032_alter_pokemonevolution_time_of_day.py Outdated

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.

Sorry maybe I explained myself poorly. Can we leave the existing migrations as they are (except for the sorting of imports) and have a single new 0034 migration?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh ok my bad will fix it tonight

Comment thread pokemon_v2/api.py
return super().retrieve(request, pk)

pass
def retrieve(self, request: Request, *args: Any, pk: str | int | None = None, **kwargs: Any) -> Response:

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, just a curiosity: is the order important here?

self, request: Request, *args: Any, pk: str,
self, request: Request, pk: str, *args: Any, 

are the same? Because we have named parameters?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not the same, order is important that keyword arguments should follow positional parameters.

in case 1 pk is explicitly a keyword argument
in 2nd its positional u can pass either as position or as kwarg

Comment thread pokemon_v2/api.py
)
class AbilityResource(PokeapiCommonViewset):
queryset = Ability.objects.all()
queryset = Ability.objects.select_related("generation")

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.

Why do we filter for generation?

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.

Oh, is this for the N+1 problem?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not filtering just prefetching/selecting you will notice a similar patter in serializer methods too where we were fetching other models in a for loop over a select_related for example a move might have bunch of version groups fetching the version group in the for loop via its model/serializer makes independent django queries for all related groups instead it can be fetched in one query just by using select_related or pre fetching

Comment thread pokemon_v2/api.py
try:
git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"], stderr=subprocess.DEVNULL).decode().strip()
except Exception:
except (subprocess.CalledProcessError, OSError, ValueError):

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.

Do we need to be so precise here? catching Exception is bad?

@Naramsim Naramsim left a comment

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.

Great, I left some comments/questions. The remaining file that I need to review is serializers.py

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.

2 participants