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

Provide a simple syntax to load resources from __here__ #259

Closed
jaraco opened this issue Jul 23, 2022 · 1 comment · Fixed by #260
Closed

Provide a simple syntax to load resources from __here__ #259

jaraco opened this issue Jul 23, 2022 · 1 comment · Fixed by #260
Labels
enhancement New feature or request

Comments

@jaraco
Copy link
Member

jaraco commented Jul 23, 2022

Currently, files() requires a parameter indicating from which package to load the resources. A common practice is to pass __package__, meaning load resources from the same package that this module is in.

When #203 is solved, it also becomes possible to use files(__name__) to mean the same thing (load resources from the same package that this module is in or for non-package modules other resources found alongside this module).

Perhaps it would be cleaner and simpler to support files() with no parameter, meaning the same thing (load resources alongside this module). No doubt, this form is the most common usage of files(). Alternately, files could accept the special value "." with the same meaning.

Either implementation would require importlib resources to infer the module from the caller's context. This feature would be an anti-feature if that couldn't be inferred reliably on all Python implementations.

@jaraco jaraco added the enhancement New feature or request label Jul 23, 2022
jaraco added a commit that referenced this issue Jul 23, 2022
@jaraco
Copy link
Member Author

jaraco commented Jul 23, 2022

I've drafted a proof of concept in https://github.com/python/importlib_resources/tree/feature/implicit-here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant