Skip to content

Add type annotations#519

Open
CoolCat467 wants to merge 18 commits intoethteck:mainfrom
CoolCat467:add-type-annotations
Open

Add type annotations#519
CoolCat467 wants to merge 18 commits intoethteck:mainfrom
CoolCat467:add-type-annotations

Conversation

@CoolCat467
Copy link

In this pull request, we add missing type annotations and fix reported mypy type issues.

@CoolCat467 CoolCat467 marked this pull request as draft February 16, 2026 03:47
@ethteck
Copy link
Owner

ethteck commented Feb 18, 2026

Hi, thanks for your PR @CoolCat467. I think it would be good to avoid changing the format of the import statements, as this will break usage of splat as a library and/or subrepo unfortunately. Keeping the scope of this to just type annotations would be ideal.

Copy link
Collaborator

@AngheloAlf AngheloAlf left a comment

Choose a reason for hiding this comment

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

Hi! Thanks for your interest in this project!

I'm a bit curious, have you used this repository before? And what game have you tried it for?

Also, CI is pretty angry at this PR, you should take a look at it.

Comment on lines -18 to -19
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a pattern we do like a lot, because it allows us to change the parameter list without changing every place where __init__ of an subclass of Segment is overriden. We only name all the parameters of the constructor when we need any of those parameters.
Please revert it.

Copy link
Author

Choose a reason for hiding this comment

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

It starts getting really nasty trying to keep the type arguments correct if I don't change this pattern. I'd like to avoid using Any as much as possible, because it completely eliminates the benefits of type checking.

"Allows to configure the section before running the analysis on it"

section = disassembler_section.get_section()
assert section is not None
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be nice to include a bit of information about this segment on the second argument of the assert, like the segment name or rom address so it is easier to debug we it failed.
There are a few examples in the repo


def cache(self):
@override
def cache(self) -> list[tuple[SerializedSegmentData | list[str], int | None]]: # type: ignore[override]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should avoid usage of # type: ignore as much as possible, unless we have a good reason for it, because it defeats the point of type hints

@@ -1,22 +1,28 @@
from typing import List, Optional
from __future__ import annotations
Copy link
Collaborator

@AngheloAlf AngheloAlf Feb 18, 2026

Choose a reason for hiding this comment

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

Just noted that from __future__ import annotations is deprecated and will be removed in the future, so it would be better to avoid introducing it here
https://docs.python.org/3.14/library/__future__.html#id2

Copy link
Author

Choose a reason for hiding this comment

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

I agree that eventually we will not need to use this as soon as we drop support for older python versions, but until we drop support for like 3.14 or something several years in the future it's perfectly acceptable to use this for having modern type annotations in projects that support old python versions.

yaml: Dict,
config_paths: List[Path],
modes: List[str],
yaml: Mapping[str, object],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why Mapping instead of dict?

Copy link
Author

Choose a reason for hiding this comment

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

Mapping is co-varient instead of contra-varient or something, unlike dict. See https://stackoverflow.com/questions/52487663/python-type-hints-typing-mapping-vs-typing-dict for more info.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure, but we don't really care about other kind of collections. Similarly to how we use list instead of Sequence.
I think we should use dict and keep it simple.

name: str,
rom_bytes: bytes,
segment_rom_start: int,
exclusive_ram_id: str | None,
Copy link

Choose a reason for hiding this comment

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

the PR makes use of this union syntax a lot but this was actually introduced in python 3.10 (source), unlike splat which (according to angheloalf) supports 3.9

Copy link
Author

Choose a reason for hiding this comment

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

Again, this is not a problem because of using from __future__ import annotations. Anything that's trying to use annotations at runtime uses something like typing.get_type_hints, which deals with string versions of annotations properly.

@AngheloAlf
Copy link
Collaborator

Well... This PR now tripled in size since yesterday (it was +500 -400, now it is +1600 -1400. yikes).
From a quick look seems like most of those changes are mostly changes in the configuration of the formatter. That kind of changes is a lot more subjective and related to the preference for each project.

I think the formatting changes should be reverted because it would be better to keep the PR focused about type hints and try to make the PR smaller.
Increasing the size of the PR overnight with changes unrelated to the original intention is bad for reviewing, consistency and such.

I'm not saying adding configurations for the formatter is a bad idea, but it adds a lot of noise and makes the PR harder to review. Each config should be discussed and agreed on, so just adding a lot of them makes the discussion harder to have.
Would be fine to move this changes to other PRs, and introduce the changes gradually.

@AngheloAlf
Copy link
Collaborator

About the overall PR, I think I won't continue to review it until at the very least half the CI checks are passing. Specially the ones that just check if the program itself can still be run or not, which currently doesn't with this PR. After all, we don't merge a PR if it doesn't have all the CI checks passing.

I have limited time for working in hobbies like this one, and I don't want to use it in reviewing an in-the-works PR.
I can still discuss stuff if you want to ask me something.

I think a better approach for this problem would be to split this into multiple, more approachable and smaller, PRs.
For example you could make a PR that enables 1 or 2 mypy lints at a time and address those first, discuss it, and if we like the changes merge and repeat.

btw, you never answered my question. What game are you using this project for? 👀

@CoolCat467
Copy link
Author

I'm not really intending on having this reviewed yet, it's not ready, still in draft mode, but I am glad nonetheless to have early feedback. Will probably revert the formatting commit in that case.

I think the idea of spinning this off into several smaller pull requests is a much better idea now that I think about it. In that case, I think I'm going to transition this particular pull request to only get what I've added so far to pass a slimmed down version of the errors to at least get the ball rolling and then start working on others that build on this one.

Not currently using splat in any of my own projects, it just looked like an interesting challenge to add type annotations. With full type annotations, mypy becomes very powerful and can help alert if new code or changed code isn't meshing with how prior things were annotated, and can help discover issues with the program before someone hits them in an edge case at runtime.

@CoolCat467
Copy link
Author

Able to get test.py to run successfully now on my machine

@ethteck
Copy link
Owner

ethteck commented Feb 21, 2026

I re-ran CI - please fix the remaining errors

@CoolCat467 CoolCat467 marked this pull request as ready for review February 21, 2026 07:22
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.

4 participants