-
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 root_io #699
base: master
Are you sure you want to change the base?
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
This reverts commit df74ff4.
@@ -3,6 +3,8 @@ | |||
|
|||
from ROOT import gSystem | |||
|
|||
from utils import convert_to_str_paths |
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.
from utils import convert_to_str_paths | |
from podio.utils import convert_to_str_paths |
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.
These should also go to where the rest of podio
modules are imported
@@ -3,6 +3,8 @@ | |||
|
|||
from ROOT import gSystem | |||
|
|||
from utils import convert_to_str_paths |
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.
from utils import convert_to_str_paths | |
from podio.utils import convert_to_str_paths |
Also these should be grouped with the rest of the podio
imports
BEGINRELEASENOTES
ENDRELEASENOTES