Skip to content

Conversation

@drisc
Copy link
Contributor

@drisc drisc commented Jul 6, 2025

This PR adds all the current endpoints along with warnings for legacy and "heavy" endpoints as defined by the API docs pages.

Most of the endpoints have checks to ensure that they either provide the expected default values or they have a valid value that won't return an error from the API.

All defs are now snake_case and the file has been formatted with black and linted with flake8.

Copy link
Member

Choose a reason for hiding this comment

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

How can we improve type safety? It looks like every method returns dict.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used dict because that is Pythons mapping type, since it's taking returned json as the result I figured using the native mapping type would be a good fit. Is there something else you would recommend for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking into this more I can define the return type to increase safety e.g using Dict[str, Any]

Copy link
Member

Choose a reason for hiding this comment

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

Dict[str, Any] is not type-safe. It's the equivalent of Record<string, any> in TypeScript. In other words, it's like saying "this can be any object".

Everything in api-js and api-kotlin is type-safe to provide a good developer experience. TypedDict should let us get similar DX benefits with Python, and it's already part of Python's standard library (Python 3.8+).

With TypedDict, IDEs can provide autocomplete and catch type errors:

response = client.get_user_points("username")
points = response["points"] # good. IDE knows this exists
typo = response["ponts"] # the IDE will show a type error, helping the dev catch their bug

Copy link
Contributor Author

@drisc drisc Jul 9, 2025

Choose a reason for hiding this comment

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

I see, so I could do something like:

from typing import TypedDict

class UserProfileResponse(TypedDict):
    User: str
    UserPic: str
    MemberSince: str
    RichPresenceMsg: str | None
    TotalPoints: int
    # etc

then use it like so: def get_user_profile(self, user: str) -> UserProfileResponse:

Copy link
Member

Choose a reason for hiding this comment

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

There are some formatting issues going on in this file. Would now be a good time to set up https://github.com/psf/black?

Copy link
Contributor Author

@drisc drisc Jul 9, 2025

Choose a reason for hiding this comment

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

I thought that I had formatted the file correctly, I used black within VS Code with Format on Save enabled. We can add black as an action on the repo with a pre-commit to make sure things are good.

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