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

gui(nviz): Type hinting to the nviz library wrapper and various related improvements #4899

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

echoix
Copy link
Member

@echoix echoix commented Dec 31, 2024

This is the PR that includes the remaining typing changes I made for almost* fully typing the wrapped native library around nviz.
Mostly, it consisted of matching the c library functions called with their implementation, either directly in source code or through the notes/signatures in the doxygen docs. The most useful improvement here, is the knowledge injected by not only specifying ids as ints, but what kind of id is expected (a point id? a vector set id? an isosurface id? etc,), in order to have type checking tools help out find cases where a wrong kind of Id is used. This mismatch analysis is not made yet, however some function docs were adjusted as they were "wrong" with respect to the actual library called. To be stricter, instead of simple int aliases, these new Id types could be defined as "NewType" (https://docs.python.org/3/library/typing.html#typing.NewType), but I don't think it is appropriate for now, there's a tiny impact from what I've read.
Non-typed functions or arguments are most probably because it wasn't possible to be sure at that time.

The "various related improvements" part comes from related typing annotations that were able to be set when analyzing the function calls when investigating the wxnviz functions. It also includes a commit that fixes #4878, that was too small to be worth a PR, considering it is almost the same as the other typing fixes of the same file.

I rebased and worked around to exclude the commits from #4880 that I thought were easier and faster to merge, but didn't get through yet after addressing the review.

The next step, that this PR enables us to do, is to see what logic errors or any type errors are left in gui/wxpython/nviz/mapwindow.py, regarding to the usages of functions in wxnviz. There are already multiple ones that I identified regarding to handling of None in some attributes, that are possible, but the ones fixed were the easiest ones that didn't involve much changes.

@github-actions github-actions bot added GUI wxGUI related Python Related code is in Python labels Dec 31, 2024
…orts

There is no reason (dependency of imports) apparent here that would prevent it from working.

Works locally in a Ubuntu 22.04 WSL on Windows
grass.script was already below gui imports in 2023
This allows static analysis of self.render dict, that contains 4 keys and all boolean values
Includes using different aliases for different type of ids, to be able to check for usage mismatches
gui.wxpython.nviz.wxnviz: Add some type hints for Texture and ImageTexture
When results of GetPointOnSurface() is None, ensure that we return None, and the other branch is assured to contain floats
@echoix echoix force-pushed the pylint-3-remaining-4 branch from 304ed41 to 8b576c7 Compare December 31, 2024 16:42
@echoix echoix requested a review from ninsbl January 2, 2025 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI wxGUI related Python Related code is in Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] GLWindow.ZoomToMap() is missing positional argument 'layers'
1 participant