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

Introducing Type Hints #199

Merged
merged 1 commit into from
Sep 9, 2024
Merged

Introducing Type Hints #199

merged 1 commit into from
Sep 9, 2024

Conversation

rgaudin
Copy link
Member

@rgaudin rgaudin commented Sep 5, 2024

As we are producing a binary extension via Cython, the regular source-based mechanism of type discovery is not available. This makes using libzim a little less pleasant for those relying on types.

This adds type stubs that we will have to manually maintain.

I had to tweak a bit the wrapper to be able to expose the get_indexdata thing. Previously, we were relying on the fact that the Item had no get_indexdata method to decide whether to use the libzim auto-index feature (relied on heavily for HTML entries).

Conditional method is not really compatible with static typing.

In order to retain functionality and API, I chose to add a get_indexdata variable on all Item, set to None. If this variable is None (no action taken), then we run the auto-index. If it is not None but returns NULL, then no index (no auto neither) If it is set and returns a proper IndexData, it is used. If the variable is missing (not sub-classing Item), run the auto-index.

In other words, behavior stays the same but type checker have a get_indexdata variable to look-for.

I don't see it as an API change and thus plan on including in 3.5.0 but please let me know what you thin

Nota: no test behavior change. changes are only to please type-checker or to silence it in cases we were not respecting it on purpose.

As we are producing a binary extension via Cython, the regular source-based mechanism of type discovery is not available.
This makes using libzim a little less pleasant for those relying on types.

This adds type stubs that we will have to manually maintain.

I had to tweak a bit the wrapper to be able to expose the get_indexdata thing.
Previously, we were relying on the fact that the Item had no `get_indexdata` method to decide
whether to use the libzim auto-index feature (relied on heavily for HTML entries).

Conditional method is not really compatible with static typing.

In order to retain functionality and API, I chose to add a `get_indexdata` variable on all `Item`, set to `None`.
If this variable is `None` (no action taken), then we run the auto-index.
If it is not None but returns NULL, then no index (no auto neither)
If it is set and returns a proper IndexData, it is used.
If the variable is missing (not sub-classing `Item`), run the auto-index.

In other words, behavior stays the same but type checker have a `get_indexdata` variable to look-for.
@rgaudin rgaudin self-assigned this Sep 5, 2024
Copy link

codecov bot commented Sep 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.49%. Comparing base (dee26e4) to head (5821694).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #199      +/-   ##
==========================================
+ Coverage   93.44%   93.49%   +0.05%     
==========================================
  Files           1        1              
  Lines         519      523       +4     
==========================================
+ Hits          485      489       +4     
  Misses         34       34              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rgaudin rgaudin marked this pull request as ready for review September 5, 2024 16:15
Copy link

@benoit74 benoit74 left a comment

Choose a reason for hiding this comment

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

LGTM, see small remark but not mandatory before merging.

README.md Show resolved Hide resolved
@rgaudin rgaudin merged commit 9ab10ba into main Sep 9, 2024
20 checks passed
@rgaudin rgaudin deleted the types branch September 9, 2024 08:21
@rgaudin rgaudin linked an issue Sep 9, 2024 that may be closed by this pull request
@rgaudin rgaudin mentioned this pull request Sep 9, 2024
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.

Add type stubs
2 participants