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 typing annotations #112

Merged
merged 13 commits into from
Sep 23, 2022
Merged

Add typing annotations #112

merged 13 commits into from
Sep 23, 2022

Conversation

ymilki
Copy link
Contributor

@ymilki ymilki commented Sep 10, 2022

Following mypy output, I typed each file until no errors were left.

Additionally added GHA for tox -e mypy to prevent regressions in PRs.

Notes

There's a circular type dependency between config.py (ConfigNamespace) and proxy.py (ValueProxy) which is guarded by TYPE_CHECKING.

While I don't explicitly test for py3.10, Protocol was moved from typing-extensions to typing so there's a version guard for the Protocol import.

In statticonfig/loader, there are many Comparators using the IComparator interface. Normally, I would turn IComparator into a Protocol, but one of the classes adds a default keyword arg to __init__ which makes it different. To facilitate typing, I opted to make the inheritance explicit instead.

Closes #108

* Add typing-extensions
* Fix assignment
* Add GHA mypy
* `IComparator` is explicitly inherited
    `* One of the comparators has a different `__init__` function
    signature so `IComparator` can't be a protocol if it were to
    represent all the comparators.
* Added `ConfigGetValue` and `NameFactory` protocols here which is used
by other files.
* ValueToken is an extension of ValueProxy
* Guard circular dependency with `staticconf/config` with
`TYPE_CHECKING`.
    * `ConfigNamespace` and `ValueProxy` refer to each other
@ymilki ymilki marked this pull request as ready for review September 10, 2022 01:06
@ymilki
Copy link
Contributor Author

ymilki commented Sep 10, 2022

Ping @benbariteau @matthewess

@ymilki
Copy link
Contributor Author

ymilki commented Sep 20, 2022

Ping @dnephin.

Final commit marks the package as typed.

Copy link

@sloane-shark sloane-shark left a comment

Choose a reason for hiding this comment

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

I thought I already gave this a shipit, my bad!

Copy link
Owner

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

Awesome!

@dnephin dnephin merged commit 23cf213 into dnephin:main Sep 23, 2022
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.

This library should have type annotations
3 participants