Hacker News new | ask | show | jobs
by gardentheory 5102 days ago
Well the lighter solution and more Pythonic solution is strong typing. If a Unicode string and a byte string could not be combined then the problem would not exist AFAIK. For example "a" + 1 is an error, why is u"a" + "s" not an error?
3 comments

> For example "a" + 1 is an error, why is u"a" + "s" not an error?

"a" + b"s" is an error in Python 3.

Sorry, that was my point. Strengthening the types in python3 solves the problem without static typing being needed at all.
ok.

Static types solve it earlier though, especially for little-exercised code paths which could be forgotten or missed in testing.

But b"s" + "a" is an error in Py3.
This just gives a different error message. It does not help to find the error source.

The programmer would probably just try to fix it via str(u"a")+"s" or u"a" + unicode("s").