Hans Ginzel writes:

 > Are there any reasons not to make scalar types iterable returning
 > the value ones?

Yes.  Scalars aren't containers.  Except strs, which are containers
all the way down. :-รพ  If we must iterate scalars, then at the very
least we should conform to existing mathematical interpretations of
scalars as containers.  For example

    for i in 3:
        print(i)

could produce

set()
{set()}
{set(), {set()}}

(or perhaps an arbitrary shuffle of those, since 3 is a scalar,
there's no order to be preserved!) and

    for i in 16853193807528738685:
        print(i)

could produce

"h"
"e"
"l"
"l"
"o"
" "
"g"
"o"
"e"
"d"
"e"
"l"

More seriously, the string non-example gives a hint at the real
reason.  Some algorithms iterate and recurse over containers of
containers of ... until they hit scalars, then they do something with
the scalars.  Such algorithms will infloop if scalars are made
iterable.  This comes up with respect to strings occasionally (even on
the dev lists where everybody knows nothing is going to be done about
one-character strings).  That kind of thing means that you're going to
have to check for types you don't want to iterate in many cases.

And it will drive type-checking and linting software mad.

Steve

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/KMY2Y3N4C2INKGPSSP7MY5GKXN7QKWEF/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to