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

Adding parse and DecodedURL docs #126

Merged
merged 9 commits into from
Apr 16, 2020
Merged

Conversation

mahmoud
Copy link
Member

@mahmoud mahmoud commented Apr 10, 2020

#125 correctly points out, hyperlink.parse() and hyperlink.DecodedURL() aren't documented, so I put together something quick.

I think we maybe talked about having URL become DecodedURL at some point, but I'm not sure it's worth waiting for that.

I think this PR basically brings the docs in line with recommended practices for using hyperlink.

Questions reviewers in the comments.

…ault argument to DecodedURL() to ease programmatic construction. Fixes #125
construct a :class:`DecodedURL`, you can use this pattern:

>>> DecodedURL().replace(host='pypi.org', path=('projects', 'hyperlink').to_text()
"http://pypi.org/projects/hyperlink"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any opinion on adding a DecodedURL.build(...) or is this a fine pattern?

docs/api.rst Show resolved Hide resolved
@mahmoud
Copy link
Member Author

mahmoud commented Apr 10, 2020

@twm if you've got a sec, please take a look and let me know what you think. thanks!

Copy link
Collaborator

@twm twm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for jumping on this so quickly! I had a few thoughts. I'm also happy to help out on either the implementation or documentation sides — just let me know.

docs/api.rst Show resolved Hide resolved
src/hyperlink/_url.py Outdated Show resolved Hide resolved
@twm
Copy link
Collaborator

twm commented Apr 11, 2020

I should say more clearly: the documentation changes here are exactly what I was looking for. Thank you!

@codecov-io
Copy link

codecov-io commented Apr 11, 2020

Codecov Report

Merging #126 into master will increase coverage by 0.25%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #126      +/-   ##
==========================================
+ Coverage   98.55%   98.81%   +0.25%     
==========================================
  Files          10       10              
  Lines        1595     2020     +425     
  Branches      187      288     +101     
==========================================
+ Hits         1572     1996     +424     
  Misses         12       12              
- Partials       11       12       +1     
Impacted Files Coverage Δ
src/hyperlink/_url.py 97.81% <100.00%> (+0.90%) ⬆️
src/hyperlink/test/test_url.py 99.71% <0.00%> (-0.11%) ⬇️
src/hyperlink/_socket.py 100.00% <0.00%> (ø)
src/hyperlink/test/common.py 100.00% <0.00%> (ø)
src/hyperlink/test/test_parse.py 100.00% <0.00%> (ø)
src/hyperlink/test/test_common.py 100.00% <0.00%> (ø)
src/hyperlink/test/test_decoded_url.py 100.00% <0.00%> (ø)
src/hyperlink/test/test_scheme_registration.py 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0153229...ca40c74. Read the comment docs.

@mahmoud mahmoud mentioned this pull request Apr 14, 2020
@mahmoud
Copy link
Member Author

mahmoud commented Apr 14, 2020

OK I forked off the AbstractURL discussion to #127. With that taken care of, I think these docs answer far more questions than they raise, so if there are no critical blockers, I'd like to get them deployed sooner rather than later. Any approvers?


url = URL.from_text(u'http://github.com/python-hyper/hyperlink?utm_source=readthedocs')
url = hyperlink.parse(u'http://github.com/python-hyper/hyperlink?utm_source=readthedocs')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I'm not a fan of parse, which can return two types, and would recommend that one use URL.from_text or DecodedURL.from_text directly instead, so this change seems like a minus to me, but I might be alone there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think parse() was added to shift recommended practice toward DecodedURLs, because they're safer. parse() returns a DecodedURL by default. I think it also looks pretty nice.

"""

def __init__(self, url, lazy=False):
def __init__(self, url=_EMPTY_URL, lazy=False):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the default? Perhaps merits discussion outside of doc changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, a couple reasons:

  1. It's more parallel with URL(), which can be instantiated without arguments to get an empty URL.
  2. This way to programmatically construct a DecodedURL, you don't need to also import URL. You can do DecodedURL().replace(...).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, and the reason for including it in these changes was because I really wanted to avoid people programmatically constructing the newly-exposed DecodedURL by doing

from hyperlink import URL, DecodedURL
DecodedURL(URL(...))

Without realizing that URL's initializer arguments aren't as rigorously decoded/encoded as the rest of DecodedURL's API.

I proposed adding a .build() or .from_parts() if we want to shift to a better pattern. For now it's either that or parse('').replace(...). I figured a default arg at least lets you explicitly use the type without an extra parse()/from_text() step.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from_parts() sounds like a good addition. I have written DecodedURL(URL()) — it's a bit awkward. Perhaps I am worrying too much (this is Python, everything is slow...) but I tend to look for APIs that avoid temporaries.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK makes sense, and yes to from_parts.

Copy link
Contributor

@wsanchez wsanchez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is an improvement, though I'm unsure why the default to DecodedURL needs to be added at all, and especially as part of this PR.

I don't need to hold things up if you disagree, though.

@mahmoud
Copy link
Member Author

mahmoud commented Apr 16, 2020

codecov is having some system issues right now, I can't get codecov to come back with the coverage. The report here is saying it's gone up and is around 98.56%. Going to admin merge on that basis.

@mahmoud mahmoud merged commit 90f888b into master Apr 16, 2020
@Kriechi Kriechi deleted the add-parse-and-decodedurl-docs branch July 25, 2020 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants