question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BytesWarning thrown in imread in 2.11.1

See original GitHub issue

There seems to be a small regression when calling imread and enabling BytesWarnings (-bb):

from pathlib import Path

import imageio

image_bytes = Path("image.png").read_bytes()
image = imageio.imread(image_bytes)

Run with:

python -bb test.py
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    image = imageio.imread(image_bytes)
  File "venv/lib/python3.9/site-packages/imageio/core/functions.py", line 159, in imread
    with imopen(uri, "ri", plugin=format) as file:
  File "venv/lib/python3.9/site-packages/imageio/core/imopen.py", line 221, in imopen
    plugin_instance = config.plugin_class(request, **kwargs)
  File "venv/lib/python3.9/site-packages/imageio/config/plugins.py", line 108, in partial_legacy_plugin
    return LegacyPlugin(request, legacy_plugin)
  File "venv/lib/python3.9/site-packages/imageio/core/legacy_plugin_wrapper.py", line 64, in __init__
    f"`{self._format.name}`" f" can not read `{self._request.raw_uri}`."
BytesWarning: str() on a bytes instance

Enabling BytesWarnings helps users catch str/bytes confusion in their own code.

Environment

Python 3.9.8

pip list
Package    Version
---------- -------
click      8.0.1
imageio    2.11.1
numpy      1.21.4
pep517     0.10.0
Pillow     8.4.0
pip        21.3.1
pip-tools  6.4.0
setuptools 57.0.0
toml       0.10.2
wheel      0.36.2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
johnthagencommented, Jan 20, 2022

@FirefoxMetzger I have only ever used the -bb flag. I think this might be a special case for the interpreter?

You could check the warnings module to see if it’s configurable there.

0reactions
FirefoxMetzgercommented, Jan 20, 2022

I implemented a fix locally; however, I currently have to call pytest via python -bb -m pytest to make sure a BytesWarning is raised.

@johnthagen Do you know if there is an option in pytest itself to enable BytesWarnings?

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found