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

Unclear error message when using pathlib.Path instance as open_slide argument #112

Closed
lorenz-gorini opened this issue Feb 9, 2021 · 0 comments · Fixed by #123
Closed

Comments

@lorenz-gorini
Copy link

lorenz-gorini commented Feb 9, 2021

Context

Issue type (bug report or feature request): Feature Request
Operating system (e.g. Fedora 24, Mac OS 10.11, Windows 10): RedHat 7
Platform (e.g. 64-bit x86, 32-bit ARM): 64-bit x86
OpenSlide Python version (openslide.__version__): 1.1.2
OpenSlide version (openslide.__library_version__): 3.4.1
Slide format (e.g. SVS, NDPI, MRXS): SVS

Details

When the user wants to open a slide, he can use:

>>> slide = openslide.open_slide("/path/to/slide/slide.svs")

but he can't provide the path as a pathlib.Path instance:

>>> from pathlib import Path
>>> slide = openslide.open_slide(Path("/path/to/slide/slide.svs"))

This raises the following error:

---------------------------------------------------------------------------
ArgumentError                             Traceback (most recent call last)
<ipython-input-12-415293724eed> in <module>
----> 1 slide = openslide.open_slide(Path("/path/to/slide/slide.svs"))

~/anaconda3/envs/nic/lib/python3.7/site-packages/openslide/__init__.py in open_slide(filename)
    386     object for other types of images."""
    387     try:
--> 388         return OpenSlide(filename)
    389     except OpenSlideUnsupportedFormatError:
    390         return ImageSlide(filename)

~/anaconda3/envs/nic/lib/python3.7/site-packages/openslide/__init__.py in __init__(self, filename)
    158         AbstractSlide.__init__(self)
    159         self._filename = filename
--> 160         self._osr = lowlevel.open(filename)
    161 
    162     def __repr__(self):

ArgumentError: argument 1: <class 'TypeError'>: Incorrect type

My opinion is that this error message is not really readable to understand the user error.
My proposal is to include the expected type and the actual type (and / or the name of the variable failing) in the message. I think this could be really helpful when debugging:

ArgumentError: argument 1: <class 'TypeError'>: Expected type 'str', got 'pathlib.Path' instead

Side note:
I really appreciate pathlib package and I think that supporting it could help other users.
I could open another issue if you share the feeling.

@lorenz-gorini lorenz-gorini changed the title Unclear Error message when using pathlib.Path instance as open_slide argument Unclear error message when using pathlib.Path instance as open_slide argument Feb 9, 2021
@jaharkes jaharkes linked a pull request Jun 3, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant