-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
compat: fspath doesn't work with pathlib.Path on Python 3.5 #2903
Comments
@MrOutis Just to clarify, we don't really try to feed pathlib.Path to fspath in the current project, right? The issue is about the non-merged patch that tries to use it in our config logic. |
@efiop , yes, currently we don't have problem with this because we use either
So it is not affecting, nor stopping the current development. Thanks for the clarification, @efiop 🙂 |
I'd say that we either close this or address it, since the patch was already implemented: diff --git a/dvc/utils/compat.py b/dvc/utils/compat.py
index 372c8d2c..4242fc00 100644
--- a/dvc/utils/compat.py
+++ b/dvc/utils/compat.py
@@ -207,6 +207,11 @@ except ImportError:
except AttributeError:
if hasattr(path_type, "__fspath__"):
raise
+
+ # Support for pathlib.Path in Python 3.5, since it doesn't
+ # implement `__fspath__`
+ if isinstance(path, pathlib.Path):
+ return str(path)
+
else:
raise TypeError(
"expected str, bytes or os.PathLike object, " Thoughts on this one, @iterative/engineering ? |
@MrOutis That patch only makes sense if it is going to be used somewhere, otherwise it is just dead code. I would combine it with a patch that actually uses it. |
So let's close it, since no one is using |
I am with @MrOutis here actually. The thing that we can't pathlib.Path(pathlib2.Path(...)) # raises exception
pathlib2.Path(pathlib.Path(...)) # raises exception Which occasionally causes issues with third-party libs expecting or providing Path-like objects, e.g. |
A possible solution would be using pathlib2 in Python 3.5 instead of stdlib pathlib. We should, however, be careful since some patches in |
@Suor Nice thing about |
How will that work with third parties, @Suor ? for example, using |
@efiop , could you remind me the reason for overwriting |
@MrOutis To show relpath, when using in messages. |
@Suor pointed out that |
I love how they are already using typing ❤️ |
fspath
is currently (0.70.0
) not working forpathlib.Path
in python 3.5 because it lacks__fspath__
implementation.We need to either fix it, or put a warning on this to prevent using
pathlib.Path
withfspath
.The text was updated successfully, but these errors were encountered: