'Hello ' + 1
doesn't return the same error message on Python 3.5 and 3.6:
TypeError: Can't convert 'int' object to str implicitly
TypeError: must be str, not int
Is it a simple change in wording or is there something more subtle behind?
Python f-strings or formatted strings are the new way to format strings. This feature was introduced in Python 3.6 under PEP-498. It's also called literal string interpolation.
Python 3.6 was released on December 23, 2016. See the changelog for a full list of changes.
Python 3 was released in 2008 which included an alternatives to formatting strings: str. format() . Fast forward to 2016, Python 3.6 formatted string literals (or f-strings) were released.
It was just some cleaning up of code that involved string objects. It also introduced some changes in the error messages when incompatible objects are used to make them a bit "more informative".
See: Issue 26057 - Avoid nonneeded use of PyUnicode_FromObject()
that introduced this change if you're interested.
There's nothing subtle here, it is still illegal and all, the author changed the error message to what he considered a bit clearer.
Edit: I created Issue 29116 - Make str
and bytes
error messages on concatenation conform with other sequences to address this specific message while also addressing the error message for bytes types that have had a similarly verbose response when we do silly things with them:
>>> b'' + ''
TypeError: can't concat bytes to str
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With