Skip to content

Improve type hints on public interface#583

Merged
typemytype merged 30 commits into
typemytype:masterfrom
roberto-arista:master
May 20, 2026
Merged

Improve type hints on public interface#583
typemytype merged 30 commits into
typemytype:masterfrom
roberto-arista:master

Conversation

@roberto-arista
Copy link
Copy Markdown
Contributor

Hey!

I've recently noticed a couple of issues with hints:

  • some **kwargs wrongly hinted as dict[str, something]
  • missing return type hints (pyright does infer most of them but mypy instead defaults to Any, so better specify them)

I've also left a few comments on the code on hints/validations that I'd like an input from you. I'll try to expose them as discussions here in the PR thread.

I propose to open a separate PR to complete the ruff integration. They can probably go in parallel.

Comment thread drawBot/drawBotDrawingTools.py Outdated
Comment thread drawBot/drawBotDrawingTools.py Outdated
Comment thread drawBot/drawBotDrawingTools.py Outdated
Comment thread drawBot/drawBotDrawingTools.py Outdated
Comment thread drawBot/drawBotDrawingTools.py Outdated
Comment thread drawBot/drawBotDrawingTools.py Outdated
Comment thread drawBot/drawBotDrawingTools.py Outdated
Comment thread drawBot/drawBotDrawingTools.py Outdated
Comment thread drawBot/drawBotDrawingTools.py
methods affected:
- `lineCap`
- `underline`
- `strikethrough`
- `writingDirection`
- `text`
- `textBox`
- `textBoxBaselines`
@roberto-arista
Copy link
Copy Markdown
Contributor Author

morning! @typemytype could you have a look at the PR? thanks : )

@justvanrossum
Copy link
Copy Markdown
Collaborator

I think you should first make sure that the CI doesn't fail. There's currently a mypy error.

@roberto-arista
Copy link
Copy Markdown
Contributor Author

Sure, I'll take care of it. I am curious to know what @typemytype thinks of the open discussions : )

@typemytype
Copy link
Copy Markdown
Owner

fixed the tests

only the fontVariations resetVariations

this removes the fontVariations(None) deprecated option after 8 years.
openTypeFeatures(None) no longer supported after 8 years of deprecation
@roberto-arista
Copy link
Copy Markdown
Contributor Author

I have updated the fontVariations to include resetVariations (and mirror the openTypeFeatures example), but then the test is failing...

@roberto-arista
Copy link
Copy Markdown
Contributor Author

I also took the liberty to move all the examples in the docstrings to newPage() from size(), since I remember it being preferred. And in this way the examples are more consistent. I didn't touch the scripts in the test folder, I can do that as well if you prefer.

@justvanrossum
Copy link
Copy Markdown
Collaborator

I also took the liberty to move all the examples in the docstrings to newPage() from size(), since I remember it being preferred

I am not aware of that preference. Either way, such a change should not be part of a PR that intends to add type annotations.

The test failure seems to be that the example script and the expected image are out of sync (script draw three lines, expected image only contains two):

image

@roberto-arista
Copy link
Copy Markdown
Contributor Author

I am not aware of that preference. Either way, such a change should not be part of a PR that intends to add type annotations.

I see your point, but since I've done some corrections to the docstrings in this PR, I thought to add this as well. Type hints add some form of functionalities for IDEs, but in the end they are documentation. I see both falling under the same umbrella. Either way, I can revert it, no problem.

@typemytype
Copy link
Copy Markdown
Owner

looks good to me!

@typemytype typemytype merged commit 71cff6d into typemytype:master May 20, 2026
1 check passed
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.

3 participants