-
Notifications
You must be signed in to change notification settings - Fork 15
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
theCapypara
wants to merge
3
commits into
main
Choose a base branch
from
capypara/typing-python
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+60
−1
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ install | |
.venv | ||
__pycache__ | ||
*.pyc | ||
*.egg-info | ||
|
||
# IDEs / editors | ||
.idea | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Python Development Support Files | ||
|
||
This directory contains support files for developing Python demos: | ||
|
||
- `requirements.txt`: | ||
Requirements for development. Contains dependency for `ruff` (linter & formatter), `mypy` (type checker) | ||
and `workbench-typestubs` (typestubs for the `workbench` module). All of these are also installed | ||
in the `re.sonny.Workbench.Devel` Flatpak (TODO: not true yet, see below.) | ||
- `mypy.ini`: | ||
Rules for `mypy` used for all demos. | ||
- `workbench-typestubs`: | ||
Python package containing typestubs for the `workbench` package which is available to demos and | ||
implements the Workbench API. | ||
|
||
## Run type checks. | ||
|
||
```sh | ||
cd python-aux | ||
pip3 install -r requirements.txt | ||
cd .. | ||
# Check single file: | ||
mypy --config-file python-aux/mypy.ini src/Welcome/main.py | ||
# Check all: | ||
mypy --config-file python-aux/mypy.ini src | ||
``` | ||
|
||
## TODO | ||
|
||
TODO: All requirements should be in the Devel Flatpak, but unsure how the | ||
typestub itself could be added there...? We might need to put that in an extra repo and add it | ||
as a module to the Devel Flatpak. Ruff is already in there. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[mypy] | ||
warn_unused_configs = True | ||
explicit_package_bases = True | ||
namespace_packages = True | ||
check_untyped_defs = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
./workbench-typestubs | ||
ruff>=0.3.0 | ||
pygobject-stubs>=2.11.0 --config-settings=config=Gtk4,Gdk4,GtkSource5 | ||
mypy>=1.9.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include workbench/py.typed | ||
recursive-include workbench *.pyi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[build-system] | ||
requires = ["setuptools"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "workbench-typestubs" | ||
version = "46.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from gi.repository import Gtk, Gio | ||
|
||
window: Gtk.Window | ||
builder: Gtk.Builder | ||
|
||
def resolve(path: str) -> Gio.File: | ||
... |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
We will need to add these casts everywhere where the concrete return type can vary.
There was a problem hiding this comment.
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