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

add compatibility with pathlib.Path to root_io #699

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Victor-Schwan
Copy link

BEGINRELEASENOTES

  • add compatibility with pathlib.Path objects to root_io

ENDRELEASENOTES

Copy link
Collaborator

@tmadlener tmadlener left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose you stumbled over this when trying to instantiate a Reader with a pathlib.Path object and it failed?

The same issue will be present in sio_io, so it should also be fixed there.

Comment on lines +25 to +34
if isinstance(filenames, list):
str_filenames = []
for f in filenames:
if isinstance(f, (str, Path)):
str_filenames.append(str(f))
else:
raise TypeError(f"Invalid filename type: {f} (type: {type(f)})")
return str_filenames

raise TypeError(f"Invalid filenames argument: {filenames} (type: {type(filenames)})")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not simply do

return [str(e) for e in filenames]

and the conversion will raise the TypeError for us in case it is not possible to do it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Do you have any objections to using os.fspath instead of str? It is better for catching wrong types, e.g. if None is passed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If reader.openFiles swallows a list of os.fspath, I have no objections.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.fspath() only returns str or bytes. I am unsure what happens if a bytes path is given to reader.openFiles. fspath is just better at throwing TypeError if the argument is not pathlike compared to str(). https://docs.python.org/3/library/os.html#os.fspath

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants