4 ms·
Reminds me of Scala Maps[0]. Edit: after reading more carefully,... > Analogously with list addition, the operator version is more restrictive, and requires t
by mk89 8y ago
Reminds me of Scala Maps[0].
Edit: after reading more carefully,...
> Analogously with list addition, the operator version is more restrictive, and requires that both arguments are dicts, while the augmented assignment version allows anything the update method allows, such as iterables of key/value pairs.
But why? Consistency in API behavior is important, and as a user I don't want to have to read that I can add lists of pairs only with assignments. I hope the draft gets fixed.
[0]: https://docs.scala-lang.org/overviews/collections/maps.html https://docs.scala-lang.org/overviews/collections/maps.html
- guitarbill 8y agoYou can always allow it later, but deprecating such a "feature" is a pain. And subtle errors/outright abuse can happen with some of these automatic coercions, so Python tends to be a bit more conservative than other dynamic languages. The most (in)famous example being comparison (edit: not addition) of an integer and `None`. Allowed in Python 2, non-intuitive IMO, and responsible for a few bugs in its time. Disallowed in Python 3: > TypeError: '<' not supported between instances of 'int' and 'NoneType'
- Sean1708 8y agoDo you mean comparison with None? Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 1 + None Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for +: 'int' and 'NoneType' >>> 1 < None False vs Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> 1 + None Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for +: 'int' and 'NoneType' >>> 1 < None Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unorderable types: int() < NoneType()
- guitarbill 8y agodoh, you're absolutely right, cheers! edited the parent for posterity, too.
- zestyping 8y agoBeing able to compare all values was useful. I miss it. None being less than everything is particularly useful.
- sametmax 8y agoIt was also a huge source of bugs. I often give an exercice prompting a number with input(), then checking it to another number in the Python for beginers course. Most students don't call int() before comparing. In Python 3, they get an error, and learn to do so. In Python 2, it seems to work sometime, and if I don't catch it, they will get in trouble one day. Just make your code explicit, it's the sane thing to do anyway.
- sametmax 8y agoIt's consistent with [] + () not working, but [* * , * * ()] works.