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

Process / return a new typed Lang class in i18n methods #183

Merged
merged 1 commit into from
Aug 2, 2024
Merged

Conversation

benoit74
Copy link
Collaborator

@benoit74 benoit74 commented Jul 30, 2024

Fix #151

Changes:

  • new i18n.Lang class to hold returned values
  • i18n.get_language_details(), i18n.get_iso_lang_data(), i18n.find_language_names() and i18n.update_with_macro now process / return a new typed Lang class
  • small fixes around renaming of i18n.NotFound to i18n.NotFoundError from previous PR (forgot changelog + few wrong docstrings)

@benoit74 benoit74 self-assigned this Jul 30, 2024
Copy link

codecov bot commented Jul 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (0573638) to head (ac9249c).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #183   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           33        33           
  Lines         1603      1640   +37     
  Branches       291       306   +15     
=========================================
+ Hits          1603      1640   +37     

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

@benoit74 benoit74 force-pushed the i18_typing branch 3 times, most recently from 085dcbb to 6e700d8 Compare July 30, 2024 13:33
@benoit74 benoit74 marked this pull request as ready for review July 30, 2024 13:34
@benoit74 benoit74 requested a review from rgaudin July 30, 2024 13:40
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.

Welcomed change!

I see a missed opportunity for a proper type here that's not a wrapper around some dict.
If you're attached to that dict-ness, then subclass dict instead ; that'd be cleaner.

CHANGELOG.md Show resolved Hide resolved
@benoit74
Copy link
Collaborator Author

The dict-ness is just the least effort path. Code is regularly updating / merging multiple properties at once, and it is a mess / very verbose to re-implement without the dict facilities (see e.g. update_with_macro with I don't know how to reimplement with a proper type). Since the main goal was to expose something more useful rather than a problem of maintainability, I considered that dict-ness was the appropriate solution.

That being that, I would also prefer to use a proper type if this does not makes the code too verbose. Shall we use pydantic BaseModel as base class? It would be a new dependency, it would help a bit, even if it would probably not solve all issues

@benoit74
Copy link
Collaborator Author

(and using a proper type was also my initial trial, but I quickly realized it was not that convenient to write)

@rgaudin
Copy link
Member

rgaudin commented Jul 31, 2024

Well I think you did not read my comment to the end and that none of your arguments make sense but given it was late when you replied, I think fresh eyes will have us agree that what I commited is simpler and has no downsides. Revert if that's not the case. I only tested via running the unit tests

@benoit74
Copy link
Collaborator Author

benoit74 commented Aug 2, 2024

I did read it, just I'm not that attached to dict, and as said I would have preferred to use a proper type that does not subclass dict.

Let's go with dict, I will learn how to do it with a proper type next time (and maybe it is just not "wishable"), I like your simplification anyway.

I'll just replace dict by Dict to prepare for the future.

@benoit74
Copy link
Collaborator Author

benoit74 commented Aug 2, 2024

Edit: I'll just replace dict by Dict to prepare for the future dict is already the future ^^

@benoit74 benoit74 merged commit b1a432a into main Aug 2, 2024
10 checks passed
@benoit74 benoit74 deleted the i18_typing branch August 2, 2024 09:22
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.

Define a type for language info
2 participants