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

2021-03-23 Thread Raymond Hettinger
Change by Raymond Hettinger : -- stage: -> resolved status: open -> closed ___ Python tracker ___ ___ Python-bugs-list mailing

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

2021-03-23 Thread Jacob Nilsson
Jacob Nilsson added the comment: For what my opinion is worth, I agree with Grégory's suggestion because the ',' part of ','.join(...) is almost as unintuitive as the problems Raymond's suggestions are trying to fix. I was going to suggest a builtin to work on both str and bytes, like

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

2021-03-21 Thread Christian Heimes
Christian Heimes added the comment: I'm also -1 and would prefer something like Grégory's proposal instead. -- nosy: +christian.heimes ___ Python tracker ___

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

2021-03-21 Thread Grégory Starck
Grégory Starck added the comment: FWIW -1 from me too. That should be solved by creating a new function IMO : def joinstr(sep, *seq): return sep.join(str(i) for i in seq) -- nosy: +g.sta...@gmail.com ___ Python tracker

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

2021-03-21 Thread Kamil Turek
Change by Kamil Turek : -- nosy: +kamilturek ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

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

2021-03-20 Thread Vedran Čačić
Vedran Čačić added the comment: Yes, I know what strong typing means, and can you please read again what I've written? It was exactly about "In the face of ambiguity, refuse the temptation to guess.", because binary operators are inherently ambiguous when given differently typed operands.

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

2021-03-20 Thread Gregory P. Smith
Gregory P. Smith added the comment: There is a lot of doubt. That should clearly raise an exception because this function is intended to only operate on strings. Trivial types examples like that gloss over the actual problem. data_from_some_computations = [b"foo", b"bar"] # probably

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

2021-03-20 Thread Emil Stenström
Emil Stenström added the comment: Terry, Gregory: The suggestion is not to change what 1 + "2" does, I fully agree that it behaves at it should. The suggestion is to change what ",".join(1, "2") does. There's no doubt that the intended result is "1, 2". That's why it's possible to coerce.

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

2021-03-20 Thread Gregory P. Smith
Gregory P. Smith added the comment: -10. I agree with Serhiy. Automatic type conversion is rarely a feature. It leads to silent bugs when people pass the wrong things. Be explicit. We are intentionally not one of those everything is really a string languages like Perl or Javascript.

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

2021-03-20 Thread Terry J. Reedy
Terry J. Reedy added the comment: I read all the responses as of this timestamp. They left me more persuaded that joining objects with a string (or bytes) is explicit enough that the objects *must* be coerced to strings. A problem with coercion in "1 + '2'" is that there is no 'must'. The

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

2021-03-20 Thread Emil Stenström
Emil Stenström added the comment: Since the proposal is fully backwards compatible I don’t think preferring the old version is a reason against this nicer API. After all, people that like the current version can continue using it as they do today. Teaching Python to beginners is a great way

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

2021-03-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: FWIW, I'm running a user poll on Twitter and have asked people to state their rationale: https://twitter.com/raymondh/status/1373315362062626823 Take it with a grain of salt. Polls totals don't reflect how much thought each person put into their

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

2021-03-20 Thread jack1142
Change by jack1142 : -- nosy: +jack1142 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

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

2021-03-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: > Of 721 uses of the join() method (excluding os.path.join()) > in the stdlib, only 10 need forceful stringification with > map(str, ...) Thanks for looking a real world code. I'm surprised that the standard library stats aren't representative of my

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

2021-03-20 Thread Batuhan Taskaya
Change by Batuhan Taskaya : -- nosy: +BTaskaya ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

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

2021-03-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Vedran, it is not what strong typing means. Strong typing means that '2'+3 is an error instead of '23' or 5. str.join() expects an iterable of strings. If some of items is not a string, it is a sign of programming error. I prefer to get an exception

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

2021-03-19 Thread Vedran Čačić
Vedran Čačić 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

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

2021-03-19 Thread Terry J. Reedy
Terry J. Reedy added the comment: I am sympathetic to the 'hiding bugs' argument in general, but what bugs would this proposal hide? What bugs does print hide by auto-converting non-strings to strings? I recently had the same thought as Raymond's: "it would be nice if str.join converted

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

2021-03-19 Thread Matthew Barnett
Matthew Barnett added the comment: I'm also -1, for the same reason as Serhiy gave. However, if it was opt-in, then I'd be OK with it. -- nosy: +mrabarnett ___ Python tracker

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

2021-03-18 Thread Raymond Hettinger
Raymond Hettinger added the comment: > What changed? It comes up almost every week that I teach a Python course. Eventually, I've come to see the light :-) Also, I worked though the steps and found an efficiency gain for new code with no detriment to existing code. Lastly, I used to

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

2021-03-18 Thread Vedran Čačić
Vedran Čačić added the comment: Does strong typing mean you should write if bool(condition): ... or for element in iter(sequence): ... or (more similar to this) my_set.symmetric_difference_update(set(some_iterable)) ? As Eric has said, if there's only one possible thing you

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

2021-03-18 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: It was proposed by newbies several times before. It was rejected because it would make errors to hide unnoticed. Python is dynamically but strongly typed, and it is its advantage. I am -1. -- nosy: +serhiy.storchaka

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

2021-03-18 Thread Eric V. Smith
Eric V. Smith added the comment: I'm +0.5. Every time this bites me, I apply the same solution, so you're probably right that str.join should just do the work itself. And it's no doubt more performant that way, anyway. And I've probably got some code that's just waiting for the current

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

2021-03-17 Thread Vedran Čačić
Vedran Čačić added the comment: I can't find it now, but I seem to remember me having this same proposal (except the part for bytes) quite a few years ago, and you being the most vocal opponent. What changed? Of course, I'm still for it. (Your second list has fourth item extra. But it's

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

2021-03-17 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- nosy: +xtreak ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

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

2021-03-17 Thread Raymond Hettinger
New submission from Raymond Hettinger : Rather than just erroring-out, it would be nice if str.join converted inputs to strings when needed. Currently: data = [10, 20, 30, 40, 50] s = ', '.join(map(str, data)) Proposed: s = ', '.join(data) That would simplify a common idiom.