Feature request: add "totuple" method
This is useful to make the result of furl hashable and thus allow dictionary and set operations on it.
This also makes it compatible with the urllib's ParseResult functionality:
In [17]: p = ParseResult(scheme='http', netloc='g.co', path='/', params='', query='', fragment='')
In [18]: {p}
Out[18]: {ParseResult(scheme='http', netloc='g.co', path='/', params='', query='', fragment='')}
In [19]: {f}
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-19-814617619e8b> in <module>
----> 1 {f}
TypeError: unhashable type: 'furl'
Wonderful idea. I'll add this.
In the interim, you can always hash on the URL string.
>>> f = furl('https://arc.io/')
>>> d = {f: 'srp'}
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'furl'
>>> d = {f.url: 'srp'}
it appears to still not be hashable as of this date. happy to use the workaround but thought to mention it in passing.
hey @cmurphy208! thinking about this more, furl objects are not immutable -- their url value can change -- and thus furl objects are not good fits to be hashable unless the hash is irrespective of the value of furl.url
- the hash of a furl object, if based on its url, will change. eg
hash(furl('https://foo.com/'))is not the same ashash(furl('https://foo.com/').set(path='path'))because the two urls differ - hash values should not change once inserted into a dict or set
thus, the only way it makes sense for furl objects to be hashable is to hash to a constant value that doesnt change with the value of furl.url, but then this doesnt make sense, as hash(furl('foo.com')) != hash(furl('foo.com')), even though their urls are the same
Looking back at this 3 year old ticket, I've sadly lost context on why this was considered useful, furl objects are not ParseResult objects. I'm going to close this, as I have no stake in this.
That said, other people have drawn comparisons to urlparse in the past, and the README does refer to urllib and urlparse. Would it be a good idea to instead add a section to the docs, comparing the libraries, showing where the similarities are, and where they differ? Then, the last comment can be an example of one difference, and using 'furl.url as the hash' as an example of a workaround.