Fix handling of filtered strings in Python 3.