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

Add proper Python typing to Welcome demo #146

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

theCapypara
Copy link
Contributor

(This is a draft because it's meant for discussion and not to be merged yet; relates to #25)

This changes the "Welcome" demo so that it passes "mypy" type checks.
To achieve this, a mypy configuration file is added and a Python package which provides type information for the "workbench" module. See notes in the README file I added for some concerns we need to clarify first.

"mypy" has "python-lsp" integration via https://github.com/python-lsp/pylsp-mypy.

@@ -19,7 +21,7 @@ def dialog_response(dialog, response):
dialog.close()


subtitle_box: Gtk.Box = workbench.builder.get_object("subtitle")
subtitle_box = cast(Gtk.Box, workbench.builder.get_object("subtitle"))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed, otherwise mypy complains:

src/Welcome/main.py:22: error: Incompatible types in assignment (expression has type "Object | None", variable has type "Box")  [assignment]
Found 1 error in 1 file (checked 1 source file)

We will need to add these casts everywhere where the concrete return type can vary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cast is just the identity function at runtime: https://docs.python.org/3/library/typing.html#typing.cast

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.

1 participant