Skip to content

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

@lorenz-gorini

Description

@lorenz-gorini

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions