-
-
Notifications
You must be signed in to change notification settings - Fork 69
Add type hints #15
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 type hints #15
Conversation
…yield, or raise in their body
…default of True or False
…is a literal int, float, str object
Co-authored-by: Jack Edge <[email protected]>
Hmmm, I was going to say "get_type_hints + pytkdocs won't work on python less than 3.9" but your pipeline ran on python 3.10 🤔 |
https://docs.python.org/3/library/typing.html#typing.TypeAlias |
Maybe it's simply because your Could you try to patch pytkdocs' loader module to add the future annotations import and see if it keeps failing? |
Removing
This doesn't fix it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, couple of observations, but none of them blocking. 👍
@@ -32,7 +33,7 @@ | |||
([10**26 * 30, True, False, "%.3f"], "2481.542 YiB"), | |||
], | |||
) | |||
def test_naturalsize(test_args, expected): | |||
def test_naturalsize(test_args: list[int] | list[int | bool], expected: str) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very specific type hint for something that's just going to be slapped into argument unpacking. 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's a bit of a jumble! Will replace with list[typing.Any]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, with this:
diff --git a/tests/test_filesize.py b/tests/test_filesize.py
index 0119d58..857a958 100644
--- a/tests/test_filesize.py
+++ b/tests/test_filesize.py
@@ -3,6 +3,8 @@
"""Tests for filesize humanizing."""
from __future__ import annotations
+import typing
+
import pytest
import humanize
@@ -33,7 +35,7 @@ import humanize
([10**26 * 30, True, False, "%.3f"], "2481.542 YiB"),
],
)
-def test_naturalsize(test_args: list[int] | list[int | bool], expected: str) -> None:
+def test_naturalsize(test_args: list[typing.Any], expected: str) -> None:
assert humanize.naturalsize(*test_args) == expected
args_with_negative = test_args
The mypy fails when run from pre-commit but only as part of the Git commit:
$ gc -m "Use typing.Any"
pyupgrade................................................................Passed
black....................................................................Passed
isort....................................................................Passed
autoflake................................................................Passed
flake8...................................................................Passed
check blanket noqa.......................................................Passed
check for merge conflicts................................................Passed
check toml...........................................(no files to check)Skipped
check yaml...........................................(no files to check)Skipped
fix end of files.........................................................Passed
pydocstyle...........................................(no files to check)Skipped
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1
tests/test_filesize.py:10: error: Cannot find implementation or library stub for module named "humanize"
tests/test_filesize.py:10: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)
setup-cfg-fmt........................................(no files to check)Skipped
pyproject-fmt........................................(no files to check)Skipped
tox-ini-fmt..........................................(no files to check)Skipped
Fine when run in pre-commit or directly as mypy:
$ pre-commit run --all-files
pyupgrade................................................................Passed
black....................................................................Passed
isort....................................................................Passed
autoflake................................................................Passed
flake8...................................................................Passed
check blanket noqa.......................................................Passed
check for merge conflicts................................................Passed
check toml...............................................................Passed
check yaml...............................................................Passed
fix end of files.........................................................Passed
pydocstyle...............................................................Passed
mypy.....................................................................Passed
setup-cfg-fmt............................................................Passed
pyproject-fmt............................................................Passed
tox-ini-fmt..............................................................Passed
$ mypy --strict .
Success: no issues found in 11 source files
Maybe I'll just leave the jumble...
Co-authored-by: coiax <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #15 +/- ##
==========================================
- Coverage 99.68% 99.08% -0.60%
==========================================
Files 9 9
Lines 635 658 +23
==========================================
+ Hits 633 652 +19
- Misses 2 6 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Of course, completely understandable.
Erm, too bad. I'm not sure what is required at this point to make |
@pawamoy Hi! Any news on this? Do you have an upstream issue to follow? |
No news, no issue (feel free to open them in relevant repositories). Didn't take the time to investigate. At this point I'd recommend trying the new handler, which does not use introspection but rather visits the AST (I don't know if you already tried it or not). |
I didn't try the new handler but happy to give it a go! What do we need to change to try it? |
You just need to depend on More information about the two handlers: https://mkdocstrings.github.io/handlers/overview/#about-the-python-handlers. |
… appear in the function signature
Thanks, that works! |
@hugovk the times in seconds are typed as |
@sodul In which function? And what version of Humanize are you using? |
@hugovk We got the issue with Sample error:
I took an other look and in a way the >>> import humanize
>>> humanize.precisedelta(0.05)
'0 seconds'
>>> humanize.precisedelta(1.05)
'1 second'
>>> humanize.precisedelta(0.05, minimum_unit="microseconds")
'0 microseconds'
>>> humanize.precisedelta(1.05, minimum_unit="microseconds")
'1 second'
>>> humanize.precisedelta(1.05, minimum_unit="milliseconds")
'1 second'
>>> humanize.precisedelta(0.05, minimum_unit="milliseconds")
'0 milliseconds' When the seconds are passed as a float it works, but only the integer part is used. That's because So at the end of the day ... the type annotation is reflecting the behavior. Personally I believe For now I can update my code to cast to |
Changes proposed in this pull request:
return value
toreturn str(value)
TODO
https://github.com/python-humanize/humanize/runs/6276428220?check_suite_focus=true