Code review comment for lp:~kai-mast/friends/links

Revision history for this message
Robert Bruce Park (robru) wrote :

Wow, congrats on the test coverage, that's really impressive ;-)

One thing that I'm a little bit confused about. You named a variable "urls_sorted" but I don't actually see any sorting going on there. Then you go on to use a concept of 'offset' in order to keep track of where each link should go, and I find it a bit sloppy.

What I'd like to see instead, is just iterate over urls_sorted in a sorted way, with descending values of 'begin' (eg, linkify the last URL first and progress backwards through the string). That way there's never an offset to have to worry about as the change in string length does not affect links that appear prior to the change being made.

Another (small) problem is that you used iter() in a useless way. Friends is python3-only, so dict.items() always returns an iter and your extra call to iter() doesn't do anything.

So instead it should probably look like this:

    for key, url in sorted(urls_sorted.items(), reverse=True):

And then...

    if content:
        message = ''.join([message[:begin], content, message[end:]])

Also, I'm slightly annoyed by the inconsistency between the _linkify_mention function which is nearly identical to other linkification techniques that are inlined in the larger function. I'm sure there can be a general purpose _linkify method that can be used to linkify all kinds of links, in a much more consistent and space-efficient manner (ie, fewer lines of code).

review: Needs Fixing

« Back to merge proposal