Author jonathan-lp
Recipients agnosticdev, bbayles, berker.peksag, eric.smith, jonathan-lp
Date 2018-03-16.10:34:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Interesting conversation

As I see it, there are two ways to solve this, both discussed above:
A) Python can compute and ValueError at parse-time
B) Python can ValueError at property-call time. (Current method)

But both have Advantages/Disadvantages.
A - Pros) - The function is more consistent with all the other Python builtins (well, the one's I've dealt with).
A - Pros) - Not carrying around a "bad" port.
A - Cons) - As Matt suggests, we could be "taking something from the user" because they may want the other values. (although in that case, the current semi-related behaviour: "Unmatched square brackets in the netloc attribute will raise a ValueError" is also potentially taking something from the user).

B - Pros) - User gets the other values even if they don't get the port.
B - Cons) - User needs to have more Try/Excepts in the code (whereever you may access the property), or to write their own wrapper function.

Given the above, of the those options I still think option (A) is better. The other values may have a reduced worth if the port is invalid (depending on the user's goal).

May I suggest a third option:
C) A flag for urlsplit/urlparse to indicate we don't want to do port validation, and to just return whatever it thinks is there. ( would return 3293849038. would return "gibberish" etc). 

This way the user can choose what behaviour they want with the bad port and test the value of the port themselves if they care (something I was going to do anyway before I discovered it was included in the builtin). Some of the url quoting functions have a similar flag ("errors") for handling bad data transparently or not.
Date User Action Args
2018-03-16 10:34:50jonathan-lpsetrecipients: + jonathan-lp, eric.smith, berker.peksag, bbayles, agnosticdev
2018-03-16 10:34:50jonathan-lpsetmessageid: <>
2018-03-16 10:34:50jonathan-lplinkissue33034 messages
2018-03-16 10:34:49jonathan-lpcreate