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

Added inline type annotations to Babel #934

Merged
merged 34 commits into from
Jan 11, 2023
Merged

Conversation

DenverCoder1
Copy link
Contributor

@DenverCoder1 DenverCoder1 commented Dec 4, 2022

This PR adds inline type annotations to the public methods and classes in Babel.

This PR tries to focus on only adding correct type annotations. There are still some Pyright warnings due to non-type-safe implementations which can be fixed at a later time.

Most of the annotations have already been reviewed and approved by typeshed.

Tested on Python 3.7 - 3.11

@DenverCoder1 DenverCoder1 marked this pull request as draft December 4, 2022 21:27
@codecov
Copy link

codecov bot commented Dec 4, 2022

Codecov Report

Merging #934 (c17f6c5) into master (6109784) will increase coverage by 0.15%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #934      +/-   ##
==========================================
+ Coverage   91.63%   91.78%   +0.15%     
==========================================
  Files          23       23              
  Lines        4279     4348      +69     
==========================================
+ Hits         3921     3991      +70     
+ Misses        358      357       -1     
Impacted Files Coverage Δ
babel/core.py 96.78% <100.00%> (+0.38%) ⬆️
babel/dates.py 92.44% <100.00%> (+0.04%) ⬆️
babel/languages.py 100.00% <100.00%> (ø)
babel/lists.py 100.00% <100.00%> (ø)
babel/localedata.py 95.96% <100.00%> (+0.09%) ⬆️
babel/localtime/__init__.py 63.15% <100.00%> (-0.95%) ⬇️
babel/localtime/_unix.py 24.13% <100.00%> (ø)
babel/localtime/_win32.py 62.26% <100.00%> (+1.47%) ⬆️
babel/messages/catalog.py 95.52% <100.00%> (+0.05%) ⬆️
babel/messages/checkers.py 80.48% <100.00%> (+0.48%) ⬆️
... and 10 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@DenverCoder1 DenverCoder1 marked this pull request as ready for review December 4, 2022 21:38
@DenverCoder1 DenverCoder1 changed the title Added type annotations for most modules Added inline type annotations to Babel Jan 6, 2023
babel/core.py Outdated Show resolved Hide resolved
babel/core.py Outdated Show resolved Hide resolved
babel/core.py Outdated Show resolved Hide resolved
babel/core.py Outdated Show resolved Hide resolved
babel/localedata.py Outdated Show resolved Hide resolved
babel/numbers.py Outdated Show resolved Hide resolved
babel/numbers.py Outdated Show resolved Hide resolved
babel/plural.py Outdated Show resolved Hide resolved
babel/plural.py Outdated Show resolved Hide resolved
babel/plural.py Outdated Show resolved Hide resolved
Copy link
Member

@akx akx left a comment

Choose a reason for hiding this comment

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

Thanks for putting this work in!

I made a bunch of suggestions around readability (you can probably use GitHub's "commit suggestions in batch" thing to apply them), and then there were some somewhat suspect types wrt. docstrings.

babel/support.py Outdated Show resolved Hide resolved
babel/support.py Outdated Show resolved Hide resolved
babel/support.py Outdated Show resolved Hide resolved
babel/support.py Outdated Show resolved Hide resolved
babel/support.py Outdated Show resolved Hide resolved
babel/units.py Outdated Show resolved Hide resolved
babel/units.py Outdated Show resolved Hide resolved
babel/units.py Outdated Show resolved Hide resolved
babel/units.py Outdated Show resolved Hide resolved
babel/util.py Outdated Show resolved Hide resolved
@DenverCoder1 DenverCoder1 marked this pull request as draft January 8, 2023 01:54
DenverCoder1 and others added 3 commits January 7, 2023 18:58
* Added more type annotations to checkers.py
* Changed str to Final[str]
* Added parse_template_string option
* Type aliases for extraction results
* Fix Final on Python 3.7 (use typing_extensions)
* Change po fileobj type
* overload get_territory_currencies return type
@DenverCoder1
Copy link
Contributor Author

I made a bunch of suggestions around readability

This is a good start, maybe we can consider running Black on the whole project to give it some consistency?

@DenverCoder1 DenverCoder1 marked this pull request as ready for review January 8, 2023 03:09
@akx akx added this to the Babel 2.12 milestone Jan 11, 2023
Copy link
Member

@akx akx left a comment

Choose a reason for hiding this comment

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

@DenverCoder1 Let's ship this! ... Can you merge/rebase once more with #943 in?

@akx akx enabled auto-merge (squash) January 11, 2023 08:51
Copy link
Member

@akx akx left a comment

Choose a reason for hiding this comment

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

🚀

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