| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
…yield, or raise in their body
…default of True or False
…is a literal int, float, str object
Co-authored-by: Jack Edge <yellowbounder@gmail.com>
|
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 🤔 |
Sorry, something went wrong.
|
typing.TypeAlias is new in 3.10, maybe mkdocstrings / pytkdocs doesn't support it yet? https://docs.python.org/3/library/typing.html#typing.TypeAlias |
Sorry, something went wrong.
|
Maybe it's simply because your TypeAlias import is type guarded? Therefore not available at runtime for get_type_hints to pick it up? pytkdocs doesn't do anything special with types (it has no particular knowledge of any other types). Could you try to patch pytkdocs' loader module to add the future annotations import and see if it keeps failing? |
Sorry, something went wrong.
Removing if TYPE_CHECKING: fixes it. I'd rather not remove it, because it would mean we need to add typing_extensions as a runtime library dependency, when it's only needed when checking types.
This doesn't fix it. |
Sorry, something went wrong.
There was a problem hiding this comment.
Looks good, couple of observations, but none of them blocking. 👍
Sorry, something went wrong.
| ], | ||
| ) | ||
| 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.
This is a very specific type hint for something that's just going to be slapped into argument unpacking. 😅
Sorry, something went wrong.
There was a problem hiding this comment.
Yeah, it's a bit of a jumble! Will replace with list[typing.Any]
Sorry, something went wrong.
There was a problem hiding this comment.
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_argsThe 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)SkippedFine 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 filesMaybe I'll just leave the jumble...
Sorry, something went wrong.
Co-authored-by: coiax <yellowbounder@gmail.com>
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.
|
Sorry, something went wrong.
Of course, completely understandable.
Erm, too bad. I'm not sure what is required at this point to make get_type_hints work. I'll need to investigate a bit more. Thank you for trying! |
Sorry, something went wrong.
|
@pawamoy Hi! Any news on this? Do you have an upstream issue to follow? |
Sorry, something went wrong.
|
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). |
Sorry, something went wrong.
|
I didn't try the new handler but happy to give it a go! What do we need to change to try it? |
Sorry, something went wrong.
|
You just need to depend on mkdocstrings-python instead of mkdocstrings-python-legacy, or to use the python extra instead of the python-legacy one 🙂 More information about the two handlers: https://mkdocstrings.github.io/handlers/overview/#about-the-python-handlers. |
Sorry, something went wrong.
… appear in the function signature
|
Thanks, that works! |
Sorry, something went wrong.
|
@hugovk the times in seconds are typed as int but they should be float. These changes are failing mypy on our side. |
Sorry, something went wrong.
|
@sodul In which function? And what version of Humanize are you using? |
Sorry, something went wrong.
|
@hugovk We got the issue with humanize==4.2.3, rolling back to humanize==4.1.0 helped. Sample error: error: Argument 1 to "precisedelta" has incompatible type "float"; expected "Union[timedelta, int]" I took an other look and in a way the int type properly reflects the actual behavior: >>> 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 _date_and_delta() does value = int(value) but I think that it could do value = float(value) instead, and then only if the type is not already a number (I suspect the intent was to cast strings to a number value). So at the end of the day ... the type annotation is reflecting the behavior. Personally I believe float is fine (it accepts int types as a subset of float), and that the code could even benefit to actually support fractions of seconds when minimum_unit allows for it. For now I can update my code to cast to int in order to satisfy mypy, even though it does not feel right: |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Changes proposed in this pull request:
TODO
https://github.com/python-humanize/humanize/runs/6276428220?check_suite_focus=true