from io import StringIO
import tokenize


def has_comment(src):
    """Indicate whether an input line has (i.e. ends in, or is) a comment.
    
    This uses tokenize, so it can distinguish comments from # inside strings.
    
    Parameters
    ----------
    src : string
      A single line input string.
    
    Returns
    -------
    Boolean: True if source has a comment.
    """
    readline = StringIO(src).readline
    toktypes = set()
    try:
        for t in tokenize.generate_tokens(readline):
            toktypes.add(t[0])
    except tokenize.TokenError:
        pass
    return(tokenize.COMMENT in toktypes)