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

Move to real classes for i18n classes for proper typing in strict mode #229

Merged
merged 3 commits into from
Dec 20, 2024

Conversation

benoit74
Copy link
Collaborator

@benoit74 benoit74 commented Dec 19, 2024

This PR is preparatory work for #212.

It is also a rework of #151 / #183 where I obviously was a bit too lazy.

Since this is ready and "significant" and isolated change, I submit it in a dedicated PR.

I've removed two tests which do not really make sense once we use real classes, and are not possible since we cannot init the class with dict values anymore.

CHANGELOG is not updated since anyway we will have to tackle this separately for 5.0.0

This has been tested locally for proper operation with pyright strict mode.

@benoit74 benoit74 self-assigned this Dec 19, 2024
Copy link

codecov bot commented Dec 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (f68d568) to head (67844f4).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #229   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           39        39           
  Lines         2439      2417   -22     
  Branches       331       322    -9     
=========================================
- Hits          2439      2417   -22     

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

@benoit74 benoit74 marked this pull request as ready for review December 19, 2024 08:21
@benoit74 benoit74 requested a review from rgaudin December 19, 2024 08:21
- Single `Language` class that takes a query and handles everything
- `get_language()` and `get_language_or_none` as goto calls to get it
- kept `find_language_names()` and `is_valid_iso_639_3()` but reusing `Language`
Copy link
Member

@rgaudin rgaudin left a comment

Choose a reason for hiding this comment

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

Thank you ; it looks good (but we need the docstrings!).

Unfortunately, looking at this makes me want to change it all. I find the API unintuitive and I dont understand why there's Lang, LangAndDetails and all those functions that looks low-level.

Actually, I've tried to reorganize it into something more user-friendly and will push one commit. You let me know what you think about it. It works (updated the tests) but we might want to reorganize the code as everything happens in a single method…

src/zimscraperlib/i18n.py Outdated Show resolved Hide resolved
src/zimscraperlib/i18n.py Outdated Show resolved Hide resolved
@benoit74
Copy link
Collaborator Author

I like the new API. I didn't wanted to totally break the old one because I (badly) assumed it was done on-purpose. But I agree it was a nightmare to read and maintain, and probably also to use. I will ask next time ^^

I add missing tests to have 100% coverage.

I propose to not mind about the fact that method is long / complex, I find it way easier to understand what we do (and hence to maintain) than what we had before or what we could have by splitting the code in multiple functions.

@benoit74 benoit74 merged commit b7b5e46 into main Dec 20, 2024
9 checks passed
@benoit74 benoit74 deleted the i18n_class branch December 20, 2024 08:54
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.

2 participants