Skip to content

Add typings to some parts of the code#96

Closed
MangoTCF wants to merge 9 commits intoC0rn3j:mainfrom
MangoTCF:main
Closed

Add typings to some parts of the code#96
MangoTCF wants to merge 9 commits intoC0rn3j:mainfrom
MangoTCF:main

Conversation

@MangoTCF
Copy link
Copy Markdown

@MangoTCF MangoTCF commented Jan 27, 2026

This PR is part 1 of many.
Files modified by me are:

tools.py
actions.py
aliases.py
config.py
mapper.py
special_actions.py
uinut.py

Other files are reformatted via ruff as per the configuration in pyproject.toml
As open as i could be to constructive criticism, as this is my first more or less serious PR.

Comment thread scc/tools.py Outdated
Comment thread scc/tools.py Outdated
Comment thread scc/tools.py Outdated
Comment thread scc/tools.py Outdated
Comment thread scc/cemuhook_server.py Outdated
Comment thread scc/actions.py Outdated
@C0rn3j
Copy link
Copy Markdown
Owner

C0rn3j commented Jan 27, 2026

You should be able to drop the format everything with ruff commit, I've taken in most of the changes that Ruff recommended, still need to later mark the areas I left out so it does not touch it on the next run.

Hopefully this does not make it too annoying to drop the commit and rebase.

I'm planning to also run ruff check --fix later to catch other easy issues.

@MangoTCF MangoTCF reopened this Jan 27, 2026
@MangoTCF
Copy link
Copy Markdown
Author

Shot myself in the foot with git a bit, everything should be a-ok now

Comment thread scc/uinput.py Outdated
Comment thread scc/uinput.py Outdated
Comment thread scc/uinput.py Outdated
Comment thread scc/tools.py Outdated
Comment thread scc/special_actions.py Outdated
Comment thread scc/special_actions.py Outdated
Comment thread scc/cemuhook_server.py Outdated
Comment thread scc/cemuhook_server.py Outdated
Comment thread scc/aliases.py Outdated
Comment thread scc/special_actions.py Outdated
Comment thread scc/mapper.py Outdated
@MangoTCF MangoTCF changed the title Add typings to some parts of the code and run a formatter on the codebase for the first time in seemingly ages Add typings to some parts of the code Jan 27, 2026
@MangoTCF
Copy link
Copy Markdown
Author

Should I infer and add a complete, really big, type to the config in config.py or is it being a dict[str, Any] enough?

@C0rn3j
Copy link
Copy Markdown
Owner

C0rn3j commented Jan 27, 2026

We can always make it more specific later if desired, Any is probably fine there

@MangoTCF
Copy link
Copy Markdown
Author

Also we really need to migrate away from PyGObject as it at the very least messes with typecheckers

And, like, the whole GTK5 release = GTK3 EOL thing

I propose Qt 6 as it looks like thay are moving in the right direction

Comment thread scc/mapper.py Outdated
Comment thread scc/aliases.py Outdated
Comment thread scc/uinput.py

def __init__(self):
self.in_use = False
super().__init__()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Do we really need to init the super class here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Linter complains :) It's better to do that for code consistency etc.

Comment thread scc/uinput.py Outdated
Comment thread scc/tools.py Outdated
Comment thread scc/special_actions.py
Comment on lines +350 to 351
# why not move size to be the second argument then?
control_with, size = DEFAULT, control_with
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It's a cursed shorthand.

>>> x, y = 1, 2
>>> x, y = 3, x
>>> print(x, y)
3 1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah, i get it, but why do
def f(a, b, c=DEFAULT, ..., shorthand_notation_thing=0):
if one can do
def f(a, b, shorthand_notation_thing=0, c=DEFAULT, ...):
?

Comment thread scc/special_actions.py

def whole(self, mapper, x, y, what):
@override
def whole(self, mapper, x: int | float, y: int | float, what: str, *_params):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why the added *_params?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

My linter says that this method "overrides in an incompatible way". There's some more errors like this, but I'd need some more experience with the codebase to be sure how to fix them

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Basically, the signatures of the methods should be compatible as per the docs which IMHO is a good idea

@C0rn3j
Copy link
Copy Markdown
Owner

C0rn3j commented Jan 28, 2026

I've unresolved some things you've set as resolved without a change/answer and added some more.

I think besides the currently open conversations, this is LGTM, so please let's get this PR in before expanding it further, it's getting hard to review, thanks!

@MangoTCF
Copy link
Copy Markdown
Author

Also to avoid having to do the whole rebasing thing on the next PR you could run ruff check --fix which would supposedly fix everything that's safe to fix.

@MangoTCF
Copy link
Copy Markdown
Author

MangoTCF commented Jan 29, 2026

@C0rn3j could you please look through the open conversations and affirm that everything is OK and my reasons for doing the things I did are valid?

@C0rn3j
Copy link
Copy Markdown
Owner

C0rn3j commented Jan 29, 2026

Did you perhaps Start a review but never sent it in? I see no comments.

Comment thread scc/uinput.py
class Keys(IntEnum):
"""Keys enum contains all keys and button from linux/uinput.h (KEY_* BTN_*)."""

# TODO: Put these back when minimum Python version is... 3.10? https://github.com/C0rn3j/sc-controller/issues/24
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Also, what's the stance with these TODOs? 3.09 is EOL as per this

Comment thread scc/uinput.py Outdated
Comment thread scc/special_actions.py Outdated
Comment thread scc/cemuhook_server.py Outdated
Comment thread scc/mapper.py Outdated
Comment thread scc/special_actions.py

def whole(self, mapper, x, y, what):
@override
def whole(self, mapper, x: int | float, y: int | float, what: str, *_params):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Basically, the signatures of the methods should be compatible as per the docs which IMHO is a good idea

Comment thread scc/tools.py Outdated
Comment thread scc/uinput.py Outdated
Comment thread scc/mapper.py Outdated
Comment thread scc/mapper.py Outdated
@MangoTCF
Copy link
Copy Markdown
Author

Yup, you're completely right -_- i need to learn how to interface with all this better

@MangoTCF
Copy link
Copy Markdown
Author

MangoTCF commented Feb 1, 2026

@C0rn3j Any updates? Or did i do something wrong again? :p

Comment thread scc/mapper.py
vendor: int = int(cfg["output"]["vendor"], 16)
product: int = int(cfg["output"]["product"], 16)
version: int = int(cfg["output"]["version"], 16)
name = cfg["output"]["name"]
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This seems unnecessarily verbose, ty can grep that this is an int.

It'd be something else if this were inside of an __init__ function, but it ain't.

I'll manually apply most of this instead of nitpicking into things further and asking to postpone some things for now, so we can get moving, so no need to edit the PR further.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That is fair, okay :D

Comment thread scc/special_actions.py
self.size = self.DEFAULT_SIZE
self.action: Action | None = None
self.timeout: float = self.DEFAULT_TIMEOUT
self.size: float = self.DEFAULT_SIZE
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

self.size looks like an int to me?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It looks like an int but it might be a float.. I didn't look into the function too much as the if len(parameters)>0 construct needs a refactoring to use default args anyways to avoid confusion and bugs

Comment thread scc/special_actions.py
Comment thread scc/tools.py
def find_button_image(name, prefer_bw=False):
def find_button_image(
name: str | None, prefer_bw: bool = False
) -> tuple[None, bool] | tuple[str, bool] | tuple[str, bool]:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

You duped the return type here

@C0rn3j C0rn3j closed this Feb 3, 2026
@C0rn3j
Copy link
Copy Markdown
Owner

C0rn3j commented Feb 3, 2026

I'll check out the ruff check --fix stuff eventually, it's a lot to go through.

Sorry if I missed anything in the PR, I tried to include what I could while fixing what seemed wrong.

I deliberately left out Sequence typings (or converted them to lists where it seemed appropriate) as frankly, I don't get them at this point and I didn't have the time to properly learn them.

Further things were left out on purpose, some were left out simply because I wasn't sure if they should be there or not and didn't have the time to go through it all

One thing to note is that I reworked the SA = COMMAND = "text" to be SA = "text"; COMMAND = SA instead, as I fear something would inevitably break otherwise.

@C0rn3j
Copy link
Copy Markdown
Owner

C0rn3j commented Feb 3, 2026

Christ, those unused imports that you deleted are actually imported via star imports in the tests.

Not a fan of this codebase if I am being honest.

@C0rn3j
Copy link
Copy Markdown
Owner

C0rn3j commented Feb 4, 2026

I've now applied almost all of the ruff check --fix fixes.

Some of them were plain out breaking things, hoping that what made it in is fine, the changeset is quite large.

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