I wrote a subclass of str like this:
class URL(str):
def __init__(self, url):
u = normalize_url(url)
print u
super(URL, self).__init__(string=u)
normalize_url() function is used for doing something like url encoding. Everything is ok, until I use json.dumps(). Here is my test code:
>>> u = URL('https://example.com/path contains space.html')
https://example.com/path%20contains%20space.html
>>> json.dumps(u)
'"https://example.com/path contains space.html"'
Why json.dumps() didn't give 'https://example.com/path%20contains%20space.html'