| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Fixes python-humanize#105 Use importlib.resources available since Python 3.9 to find the location of the locale folder containing the translations.
|
I tried to use __package__ initially, but the docs suggest to use __spec__.parent instead. https://docs.python.org/3/reference/import.html#package__ The tests cover when __spec__ is None or even if it's missing. As __spec__.parent is read-only , I cannot make a test which sets a different value for it. |
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks for this!
Let's do some tuning to speed up with lazy imports, which can be important for CLIs where you want a quick response time.
Using https://github.com/nschloe/tuna we can visualise the import times:
python -m pip install tuna
python -c "import humanize" && python -X importtime -c "import humanize" 2> import.log && tuna import.logHere's main:
Here's this PR:
With the suggestions:
Sorry, something went wrong.
Improve import times Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
|
Hi, Thank you for the review. I had not considered the CLI aspect of humanize. That's a good point. Now a CLI user will pay the price of importing importlib.resources at some point obviously. But I can see how if TYPE_CHECKING:
import os
import pathlibis really useful here. Thank you for showing me tuna. I did not know this tool, and I've used snakeViz in the past, so it's great to see a better alternative. Also this is the first time I see python -X importtime -c "..." in use. I learnt something new today! 👏 |
Sorry, something went wrong.
|
I can also imagine some CLI users don't use i18n so might not run touch this. Even for code that might run more often, lazy imports can make --help a bit faster too. Yeah, tuna is really nice for visualising import times along with -X importtime :) Thanks for the PR! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes #105
Changes proposed in this pull request: