Conversation
|
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. |
AngheloAlf
left a comment
There was a problem hiding this comment.
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.
| def __init__(self, *args, **kwargs): | ||
| super().__init__(*args, **kwargs) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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], |
There was a problem hiding this comment.
Why Mapping instead of dict?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
|
Well... This PR now tripled in size since yesterday (it was +500 -400, now it is +1600 -1400. yikes). 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. 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. |
|
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 think a better approach for this problem would be to split this into multiple, more approachable and smaller, PRs. btw, you never answered my question. What game are you using this project for? 👀 |
|
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. |
|
Able to get |
|
I re-ran CI - please fix the remaining errors |
In this pull request, we add missing type annotations and fix reported mypy type issues.