-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
ENH: Add support for third-party path-like objects by backporting os.fspath #12157
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
Conversation
fid = file.open("rb") | ||
own_fid = True | ||
else: | ||
if hasattr(file, 'read'): | ||
fid = file | ||
own_fid = False |
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.
Some alternatives to this block, and the similar ones below
This patch:
if hasattr(file, 'read'):
fid = file
own_fid = False
else:
fid = open(os_fspath(file), "rb")
own_fid = True
Alternative 1 (smaller diff);
if isinstance(file, os_PathLike):
file = os_fspath(file)
if isinstance(file, basestring):
fid = open(file, "rb")
own_fid = True
else:
fid = file
own_fid = False
Alternative 2 (no duck-typing):
if isinstance(file, io.IOBase):
fid = file
own_fid = False
else:
fid = open(os_fspath(file), "rb")
own_fid = True
elif is_pathlib_path(filename): | ||
if is_pathlib_path(filename): | ||
# special case - if we were constructed with a pathlib.path, | ||
# then filename is a path object, not a string | ||
self.filename = filename.resolve() |
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.
This is the only remaining use of is_pathlib_path
, which is needed for a weird special case.
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.
Since we need is_pathlib_path
anyway, PR #11348 more straight-forward and simpler.
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.
This is orthogonal to PR #11348 - this makes numpy work with backports of pathlib too / third-party objects implementing __fspath__
too.
34a4160
to
a47aa9e
Compare
Azure is missing from the CI list on this and some other recent PRs -- I'll open an issue. |
Coverage failures are garbage, and caused by us not collecting coverage data in python < 3.6 |
@tylerjereddy: did you find a workaround to make the CI run? |
Closing/reopening to restart CI |
@eric-wieser No, but maybe Microsoft did something since their engineers were investigating. Looks like Azure is running on all recent PR triggers including updates / force pushes, etc. |
Note that the only way to make CI pass here is to collect and merge coverage data on multiple python versions - it's impossible to exercise python3.5-only code if we only collect coverage data on 3.6. Perhaps we should exclude |
It would be nice to cover the other Python versions, but not sure if it is worth the effort and / or risk that we break the fragile codecov stuff as happened with SciPy. I'd probably lean toward leaving most files in the report but having the reviewer skeptical of cov-related failures, but probably not a big issue either way as long it is not a big slippery slope with progressive blacklisting of lots of files on the report. |
At this point I prefer the current situation - when codecov fails the commiter/reviewer asks to ignore the fail. |
LGTM - will merge soon if there are no other comments |
Thanks Eric |
In response to #11348