Why not make str.join() coerce the items in its iterables

And you would save an incredible five characters! What a difference that makes! Right?

Or you can write a helper function once, and save about 20 characters: join(mything).

What you are proposing is a form of weak typing. Python is a strongly-typed language, with very little weak typing, and (almost?) all of that is in automatic coercion of different numeric types.

It is never automatic coercion of strings to ints, or ints to strings (for example). Weak typing has the benefit of saving keystrokes. Strong typing has the benefit of preventing bugs. Some languages are even stronger than Python, and don’t allow automatic numeric coercion.

In the last few weeks, this same issue has come up at least twice, and I responded both times:

Unless you have a new and better argument than “save some keystrokes”, I don’t think there is much to discuss here that hasn’t already been discussed before.

  • this proposal introduces weak typing;
  • its not clear that we should want str rather than repr or ascii or something else;
  • string joining is a low-level API, and should be explicit;
  • writing your own convenience function is literally two lines of code.

If you do have a strong argument for weak typing (heh pun intended) please tell us.

11 Likes