Skip to content

Commit

Permalink
url: Clean up logic in trim_url()
Browse files Browse the repository at this point in the history
Python 2 doesn't like `thing is unicode`; it wants `thing == unicode`.
Of course, it just works with regular str in both py2 and py3… Oh well.

This is another find from @Exirel's overhaul of URL handling for 7.x.

As long as I was touching the line anyway, I added parentheses to make
the operator precedence explicit. Likely unnecessary, but probably
easier to read by some small measure.
  • Loading branch information
dgw committed Mar 24, 2019
1 parent 707c5d8 commit fa42aef
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion sopel/modules/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def trim_url(url):

# clean unmatched parentheses/braces/brackets
for (opener, closer) in [('(', ')'), ('[', ']'), ('{', '}'), ('<', '>')]:
if url[-1] is closer and url.count(opener) < url.count(closer):
if (url[-1] == closer) and (url.count(opener) < url.count(closer)):
url = url[:-1]

return url
Expand Down

0 comments on commit fa42aef

Please sign in to comment.