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

Fix deprecation warning in importlib.resources #2449

Closed
wants to merge 2 commits into from
Closed

Fix deprecation warning in importlib.resources #2449

wants to merge 2 commits into from

Conversation

masklinn
Copy link

read_binary was deprecated in 3.11: https://docs.python.org/3/library/importlib.resources.html#deprecated-functions

The files API was added in 3.9, use it to implement reimplement read_binary following documentation guidance, it's not exactly how the stdlib implements it but since instantiate_template only calls read_binary with an explicit string it seems good enough.

Ideally it would make sense for the ViaTemplateActivator to instantiate a files during initialisation, then just get the relevant resource from that, but that's a much larger API divergence, so seems easier this way unless a shim is implemented the other way around (that is an object with a joinpath / __truediv__ and a read_bytes is implemented on top of read_binary for pre-3.9).

Thanks for contributing, make sure you address all the checklists (for details on how see development documentation)!

  • ran the linter to address style issues (tox -e fix_lint)
  • wrote descriptive pull request text
  • ensured there are test(s) validating the fix
  • added news fragment in docs/changelog folder
  • updated/extended the documentation

masklinn and others added 2 commits November 24, 2022 22:06
`read_binary` was deprecated in 3.11: https://docs.python.org/3/library/importlib.resources.html#deprecated-functions

The `files` API was added in 3.9, use it to implement reimplement
`read_binary` following documentation guidance, it's not exactly how
the stdlib implements it but since `instantiate_template` only calls
`read_binary` with an explicit string it seems good enough.

Ideally it would make sense for the `ViaTemplateActivator` to
instantiate a `files` during initialisation, then just get the relevant
resource from that, but that's a much larger API divergence, so
seems easier this way unless a shim is implemented the other
way around (that is an object with a `joinpath` / `__truediv__`
and a `read_bytes` is implemented on top of `read_binary` for
pre-3.9).
@masklinn
Copy link
Author

Ah I see there's already a PR at #2448, i thought to check the issues but not the PRs, sorry 'bout that.

@masklinn masklinn closed this Nov 24, 2022
@masklinn masklinn deleted the patch-1 branch November 24, 2022 21:09
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.

None yet

1 participant