Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use versionadded
  • Loading branch information
mahmoud committed Apr 11, 2020
commit 2bae6f641696934eafb447c162d4905471d766fc
4 changes: 2 additions & 2 deletions src/hyperlink/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -1787,7 +1787,7 @@ class DecodedURL(object):
... host=u'pypi.org', path=(u'projects', u'hyperlink')).to_text())
https://pypi.org/projects/hyperlink

*(New in 18.0.0)*
.. versionadded:: 18.0.0
"""
def __init__(self, url=_EMPTY_URL, lazy=False):
Comment thread
mahmoud marked this conversation as resolved.

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

# type: (URL, bool) -> None
Expand Down Expand Up @@ -2137,7 +2137,7 @@ def parse(url, decoded=True, lazy=False):
default, `lazy=False`, checks all encoded parts of the URL
for decodability.

*(New in 18.0.0)*
.. versionadded:: 18.0.0
"""
enc_url = EncodedURL.from_text(url)
if not decoded:
Expand Down