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

Allow joining URL and pathlib.Path #185

Closed
ukch opened this issue Apr 20, 2018 · 5 comments
Closed

Allow joining URL and pathlib.Path #185

ukch opened this issue Apr 20, 2018 · 5 comments
Labels

Comments

@ukch
Copy link

ukch commented Apr 20, 2018

Given the following URL and Path objects:

>>> url = URL("http://whatever/foo")
>>> path = pathlib.Path("bar/baz")

I would expect them to be joinable using code such as:

>>> url / path
URL('http://whatever/foo/bar/baz')

Instead, I receive this traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    url / path
  File "/path/to/lib/python3.6/site-packages/yarl/__init__.py", line 281, in __truediv__
    name = self._PATH_QUOTER(name)
  File "yarl/_quoting.pyx", line 226, in yarl._quoting._Quoter.__call__
TypeError: Argument should be str
@asvetlov
Copy link
Member

How do you want to join absolute path?

@ukch
Copy link
Author

ukch commented Apr 24, 2018

Currently, attempting to join a (string) path starting with a slash onto an URL raises ValueError: Appending path starting from slash is forbidden. I would say the same behaviour should occur with absolute Path objects.

@asvetlov
Copy link
Member

Another question is: should symlinks be resolved?

Now I have a feeling that url / str(path) is simple and good enough. Why do we need to blow up the API?

@asvetlov
Copy link
Member

asvetlov commented Oct 8, 2019

I have a feeling that the request is out of the library scope.

@Bobronium
Copy link

I stumbled upon this issue while trying to answer this question: is pathlib.Path suitable for dealing with url path?

The immediate concern that I have is that on windows str(pathlib.Path('foo') / 'bar') would result in a 'foo\bar'.

So, answering my own question: you probably shouldn't use pathlib.Path as url path constructor.

But you desperate to do otherwise, using pathlib.PurePosixPath should at least avoid problem with separator described above.

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

No branches or pull requests

3 participants