We definitely don’t use any deprecation policy against exception messages but I remember being told to avoid changing message strings in a 3.x branch after 3.x.0 was released. No problem changing the message in 3.x+1.
IIRC We’ve changed exception message strings when the existing ones aren’t good enough and are actively confusing users before - but this seems rare and only likely to come up for a new exception that code isn’t likely to have had time to depend on the message of. I consider an exception message that is just plain wrong to be a Bug to be fixed in bug fix patch releases. Adding more detail to an otherwise correct existing message is Feature territory. Otherwise that general policy of avoiding error message, str, and repr, changes makes sense to me.
technically correct… but I suggest we avoid that wording just in case it gives anyone the idea that they should not feel dirty when they depend on the content of an error message.
I agree that in a stable version such as Python 3.13.x, error messages must NOT change. In a new major version, we can change it, even it should be discouraged if it’s for dubious reasons For example, just add or remove a trailing dot sounds that it’s not worth it. Fixing a typo or grammar sounds likr a better reason to me.
A few months ago I improved a dataclasses exception by adding more info at the end of it. I considered it an enhancement and did not backport. I think Victor’s description is a reasonable one (assuming “major version” describes all 3.13 versions, for example).
Error messages can be changed as a side effect of a bug fix which do not change any error message directly. Just the code now uses different function which produces different error message, or handles arguments in different order (both produce errors, but with different messages). I hope that the new policy will not become an obstacle in the way of bugfixes.
My understanding has been that we do not change message classes in bugfix releases unless it is a bugfix that really needs backporting, which has been very rare, and even rarely in new releases. But messages are more often changed and are better to not be depended on.
In general, if the users are net better-off, we should do it. In this case, the likelihood by perhaps a 100 to 1 is that a user will be reading the exception message with human eyes rather than making code that parses it and depends on the exact wording and spacing.
Also, we already have an established practice from doctest to add a ... in tracebacks specifically to avoid a dependency on exact wording.
Lastly, we should be reminded that every backport changes something for someone. I don’t see any reason to single out exception messages as being off limits while actual behavioral changes (bug fixes) are routinely backported. Readability fixes are bugfixes,
For me, it’s the same problem than adding new warnings after beta1: projects rely on the exact error message, especially tests. I already saw code checking for the same exact full error message to look for a specific error. doctests is a good example but not the only one. Yeah, it’s a bad pattern, but people use it.
OK, thanks for your feedback! Based on what was said here, it’s clear there isn’t enough consensus for a black & white rule. Therefore, instead of including exception message strings in PEP 387, I’ll amend the dev guide to say that exception types and exception message strings are often considered API by user code, and as such, changes to them should be carefully considered.
Perhaps clarify that “changes to them should be carefully considered” really only applies to readability edits. If the error message is flat-out wrong, misspelled, or misleading, we can and will fix it.
Perhaps also add a note that this is primarily about reduction of harm and minimizing negative effects on users. We still do emphatically recommend that users treat docstrings, exception messages, and line numbers as implementation details that SHOULD NOT be relied upon.
We know that some users don’t follow best practices and so we will try to reduce the impact, but that doesn’t make it a recommended practice. You really don’t want the PEP to become a license for people to believe that they should rely on message wording.
“If you jaywalk, we will stop and let you cross, but really, don’t jaywalk, it’s not safe.”