[issue43535] Make str.join auto-convert inputs to strings.

Vedran Čačić report at bugs.python.org
Sat Mar 20 01:31:39 EDT 2021


Vedran Čačić <vedgar at gmail.com> added the comment:

Matthew: can you then answer the same question I asked Serhiy?

The example usually given when advocating strong typing is whether 2 + '3' should be '23' or 5. Our uneasiness with it doesn't stem from coercions between int and str, but from the fact that + has two distinct meanings.

Of course, binary operators are always like that, even if it's not obvious, since there's always a tension created by difference of types of the left and right operand. Even if it's obvious that 2 - '3' should coerce the second argument to int since str doesn't define -, this can't be a general rule because e.g. set does (what about 2 - {3}?).

But method calls (and many protocols) are _not_ of that kind. As I said above, my_set ^ some_list makes us uneasy (even though list doesn't implement ^), but my_set.symmetric_difference(some_list) doesn't, simply because there is no ambiguity: there is only one thing we could have meant.

The same can be said about "for x in not_an_iterator", or "if not_a_bool".

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43535>
_______________________________________


More information about the Python-bugs-list mailing list