You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been using importlib since the days of the old interface so I preface by saying I may be doing something wrong. In the last week my unit tests started failing with a compile error in this chunk of code here:
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/importlib_resources-5.10.0-py3.6.egg/importlib_resources/_common.py:46: in wrapper
return func(anchor)
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/importlib_resources-5.10.0-py3.6.egg/importlib_resources/_common.py:56: in files
return from_package(resolve(anchor))
/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/importlib_resources-5.10.0-py3.6.egg/importlib_resources/_common.py:[112](https://github.com/MyreMylar/pygame_gui/actions/runs/3255020934/jobs/5343897993#step:5:113): in from_package
spec = wrap_spec(package)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
package = 'pygame_gui.data'
def wrap_spec(package):
"""
Construct a package spec with traversable compatibility
on the spec/loader/reader.
Supersedes _adapters.wrap_spec to use TraversableResourcesLoader
from above for older Python compatibility (<3.10).
"""
from . import _adapters
> return _adapters.SpecLoaderAdapter(package.__spec__, TraversableResourcesLoader)
E AttributeError: 'str' object has no attribute '__spec__'
it seems clear that it is not expecting a string at this point, but the same code on my side is compiling and testing happily on 3.7. I also notice that a new version of importlib_resources came out in the past week so I'm assuming this is related to my new failure.
The intention here being to load a font resource from a package, read it as bytes into a BytesIO object and then use that to create a pygame freetype font object, location.package and location.resource are both strings.
Am I doing something wrong here or is this a bug?
The text was updated successfully, but these errors were encountered:
It sure does seem like a bug, except for one key factor:
Since 5.5.0, importlib_resources requires Python 3.7 or later. This requirement is declared in metadata, which ideally should prevent the installation of these newer versions on older Pythons.
Since you're not able to replicate the issue on Python 3.7 or on older importlib_resources, I don't believe you have a supported use-case.
Still, that doesn't explain why you're encountering the error.
Oh, I bet I know what the issue is. importlib_resources 5.10 uses single dispatch to resolve a package "anchor" to a module, and it uses the type annotations to decide, capability that was added in Python 3.7. Because type annotations aren't honored on Python 3.6, it means that importlib_resources._common.resolve will only resolve a ModuleType parameter.
I'm slightly surprised that resolve(<str>) doesn't create a type error when it's cast to a ModuleType. But indeed, that seems to be how cast works:
Hello,
I've been using importlib since the days of the old interface so I preface by saying I may be doing something wrong. In the last week my unit tests started failing with a compile error in this chunk of code here:
it seems clear that it is not expecting a string at this point, but the same code on my side is compiling and testing happily on 3.7. I also notice that a new version of importlib_resources came out in the past week so I'm assuming this is related to my new failure.
Here is where I'm using it in my code:
The intention here being to load a font resource from a package, read it as bytes into a BytesIO object and then use that to create a pygame freetype font object,
location.package
andlocation.resource
are both strings.Am I doing something wrong here or is this a bug?
The text was updated successfully, but these errors were encountered: