Use `files()` to open *-table JSONs (importlib deprecated `open_text`)
cardoso-neto opened this issue ยท 2 comments
cardoso-neto commented
I'm using python 3.11 and I'm getting these a lot:
> multiformats_config/multicodec.py:80:
>> with importlib_resources.open_text("multiformats_config", "multicodec-table.json", encoding="utf8") as _table_f:
> multiformats_config/multibase.py:53
>> with importlib_resources.open_text("multiformats_config", "multibase-table.json", encoding="utf8") as _table_f:
DeprecationWarning:
open_text is deprecated. Use files() instead.
Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
And since I'm here, let me state that this is the best implementation of the multiformats protocol I've seen and it is only thanks to this package that I was able to get multiformats adopted where I work.
cardoso-neto commented
Fix could look like this for multibase.py
:
pkg_dir = importlib_resources.files("multiformats_config")
# then either joinpath
with pkg_dir.joinpath("multibase-table.json").open(encoding="utf8") as _table_f:
# or slash operator
with (pkg_dir / "multibase-table.json").open(encoding="utf8") as _table_f:
sg495 commented
Thanks for spotting this! (and for the compliment ๐). We've only recently moved to 3.11 ourselves, and this library hasn't yet been migrated. We'll get to it shortly ๐.