Message389144
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". |
|
Date |
User |
Action |
Args |
2021-03-20 05:31:39 | veky | set | recipients:
+ veky, rhettinger, terry.reedy, eric.smith, mrabarnett, serhiy.storchaka, pablogsal, xtreak |
2021-03-20 05:31:39 | veky | set | messageid: <1616218299.83.0.765773601988.issue43535@roundup.psfhosted.org> |
2021-03-20 05:31:39 | veky | link | issue43535 messages |
2021-03-20 05:31:38 | veky | create | |
|