Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Using __name__ on a non-package module results in "not a package" error #60

Copy link
Copy link
@jaraco

Description

@jaraco
Issue body actions

In GitLab by @jaraco on May 18, 2018, 11:36

Coming from pkg_resources, I'd previously used __name__ as the initial parameter:

>>> import pkg_resources
>>> import queso.validator.tests.test_options
>>> pkg_resources.resource_stream(queso.validator.tests.test_options.__name__, 'colliding questions.json')
<_io.BufferedReader name='/Users/jaraco/Dropbox/code/yg/G/queso/queso/validator/tests/colliding questions.json'>

But in importlib_resources, this approach doesn't work.

>>> importlib_resources.read_binary(queso.validator.tests.test_options.__name__, 'colliding questions.json')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jaraco/Dropbox/code/yg/G/queso/.tox/py36/lib/python3.6/site-packages/importlib_resources/_py3.py", line 142, in read_binary
    package = _get_package(package)
  File "/Users/jaraco/Dropbox/code/yg/G/queso/.tox/py36/lib/python3.6/site-packages/importlib_resources/_py3.py", line 40, in _get_package
    raise TypeError('{!r} is not a package'.format(package))
TypeError: 'queso.validator.tests.test_options' is not a package

In other words, importlib_resources seems to be more stringent about the input, requiring the parameter to be a package and not simply a module.

Is this limitation intentional? If so, the migration docs should include a note about this incompatibility.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiwontfixThis will not be worked onThis will not be worked on
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.