Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding type hinting? #152

Open
RedBearAK opened this issue Apr 10, 2023 · 0 comments
Open

Adding type hinting? #152

RedBearAK opened this issue Apr 10, 2023 · 0 comments
Labels
enhancement New feature or request request Feature request

Comments

@RedBearAK
Copy link
Contributor

@joshgoebel

I've recently discovered that type hinting, while it doesn't actually do that much as far as how the code runs, can work minor miracles in getting an IDE like VSCode to finally "know" where a lot of attributes, methods and function calls actually come from.

This can be enormously helpful when trying to understand what's happening in the code. In VSCode you can even Cmd+Click on the names of the objects it "understands" and it will take you right to where the object is defined, or show you the list of references.

It was a big jump for me to understand that type hinting was not just about maybe helping a pre-compiler throw a warning that an argument was not receiving an int or whatever. Turns out it goes way beyond that, and I can make a bunch of "generic" function calls and unhighlighted attributes/methods light up with correct highlight colors, and have useful information available, just by type hinting the appropriate class like this:

def log_combo_context(combo: Combo, ctx: KeyContext, keymap: Keymap, _active_keymaps: List[Keymap]):

This example cleared up a lot of incomplete highlighting in the defined function. But most functions only need one or two of the arguments to be type hinted to fix things that VSCode can't identify.

I've been able to clear up at least 90% or more of the unidentified objects in a couple of modules already, just by figuring out what kind of object to use for the type hinting. Would you have any objection to receiving a few PRs that just add some of this type hinting to different parts of the project?

@RedBearAK RedBearAK added enhancement New feature or request request Feature request labels Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request request Feature request
Projects
None yet
Development

No branches or pull requests

1 participant