-
Notifications
You must be signed in to change notification settings - Fork 60
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 python readers #699
Conversation
There was a problem hiding this 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.
python/podio/root_io.py
Outdated
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)})") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
576f58f
to
cb01730
Compare
d3df4e5
to
cb942e9
Compare
This reverts commit df74ff4.
ec9548b
to
2a65139
Compare
* add compatibility with pathlib.Path to root_io * outsource TypeError handling to os.fspath * add pathlib compatibility in sio_io as well * sio_io: only store first path in list returned by convert_to_str_paths * make ruff import sorting happy * outsource convert_to_str_paths * Fix imports to be absolute * Add module docstring to fix pylint complaints
BEGINRELEASENOTES
ENDRELEASENOTES