-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
better name for re.error Exception class. #83162
Comments
better error/exception name for re.compile error. Currently the error raise by re.compile when it fails to compile is
This is quite disturbing as most exception start with an uppercase and have a tiny bit more descriptive name. Would it be possible to have it renamed as something more explicit like |
It is common practice that the module specific exception is called just "error". There is nothing wrong with this. I do not see a need to introduce a different alias. |
See also the discussion about renaming json.loads(): https://mail.python.org/archives/list/python-ideas@python.org/thread/EJTIVQ2ZFSVHALTLRGFCOMOYGZYMKGQU/ |
Most of the module specific classes are if a novice sees :
It will be relatively tough or them to figure out that Also it's not because something works that you can't improve it ... |
Since it affects more than one module I suggest to discuss the idea about renaming exceptions of the Python-Ideas maillist first. Until different decision be made I am closing. Personally I think this is a duplicate of just discussed and rejected idea. |
Thanks for the advice I've done that ! Have a good day. |
Reopened after discussing on Python-ideas: https://mail.python.org/archives/list/python-ideas@python.org/thread/64NHNY6RD4HQWBSBV6J7XIN7UAHNTQBR/. |
Thanks Serhiy, Here is a rough idea of how many places would be touched by renaming in the Carreau@59e4c51 (50 additions and 42 deletions.). I haven't found any places that need changes in the C code, and need to polish documentation, rebuild and run the test suite before sending a PR. |
Strictly speaking not all of those _need_ to be touched given the old name is always going to exist for backwards compatibility. But I agree that we should update them as part of this regardless. I'd go forward with a PR. The only fallout I expect a change like this to have on users is in the very odd test scenario where someone has hardcoded the error name in a string. That is rare, especially for an re.error which is generally not an expected exception. |
I am not sure about the new name. "re" is an abbreviation, so if include it in the exception name it should be "RE". I am not sure what name is better: RECompileError, REParseError, RESyntaxError, REError, CompileError, ParseError, SyntaxError or Error. json raises JSONDecodeError, ElementTree raises ParseError, other xml modules raise ExpatError, csv raises Error, configparser raises subclasses of Error. Many modules (at least 18: aifc, binhex, concurrent.futures, configparser, copy, cvs, ftplib, locale, mailbox, shutil, sqlite, sunau, test.support, uu, wave, webbrowser, xdrlib, xmlrpc.client) have an exception named just Error for module-specific errors. |
RECompileError, REParseError, RESyntaxError, REError, CompileError, ParseError are all fine with me. SyntaxError would be super confusing IMHO. aifc, binhex, sunau, uu, xdrlib might be removed with PEP-594, And I find I would also add that being able to search and find all occurrences of a given exceptions is useful, and that Error is too generic. Let me know your choice and I can rename. |
Yes, aifc, sunau, uu and xdrlib made the list and will be deprecated in 3.11 and removed in 3.13. See PEP 594 – Removing dead batteries from the standard library and #91217. binhex isn't part of the PEP 594 because it was already deprecated in 3.9 and has been removed from 3.11: https://docs.python.org/3.11/whatsnew/3.11.html?highlight=binhex#removed Edit: pinging the nosy list after the bpo migration: @gpshead, @ezio-melotti, @serhiy-storchaka, @Carreau, @Sourabh025 |
@Carreau I see that you've closed your PR; would you still like to work on this? It seems that your PR was mostly done, and just required finalizing the actual exception name. |
I've brought the above patch in line with the current main branch as a draft PR - thanks again @Carreau. However, before I make any changes I'd like to see if we can agree on the new exception name. Looking at other popular libraries across several languages, there are several variations such as Java's This leaves us with I imagine users will most likely see this exception due to syntax issues with the expression, and some libraries make the distinction that a compilation error is related to an invalid encoding vs. a syntax error. So with that in mind, plus @barneygale's point that it could be read as recompile error, I'd like to propose using cc @serhiy-storchaka, @gpshead as you've participated in these discussions before as well. |
I'm not feeling like there is a lot of value in doing this anymore. If I were choosing a new name my logic would look like:
So I expect many will continue to type |
I think for me when looking at this issue, the benefit of introducing this would be the additional clarity for beginners, as an error like this RESyntaxError: nothing to repeat at position 0 would be more clear than what we have currently error: nothing to repeat at position 0
Currently that would be correct as
I can understand that, but as you mentioned for those folks |
We have |
I think What I do like about So what I'm thinking is this:
Thoughts? |
I prefer PatternError over RESyntaxError over RECompileError |
Renamed re.error for clarity, and kept re.error for backward compatibility. Updated idlelib files at TJR's request. --------- Co-authored-by: Matthias Bussonnier <mbussonnier@ucmerced.edu> Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
I merged the near-minimal PR with re.error 'updated' only in idlelib. I will do adjusted backports of the idlelib changes to keep the main bodies of its files in sync and then close. |
Backport idlelib part of python#101677 with simple rename.
…ythonGH-112987) Backport idlelib part of pythonGH-101677 with simple rename. (cherry picked from commit fd3b894) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Renamed re.error for clarity, and kept re.error for backward compatibility. Updated idlelib files at TJR's request. --------- Co-authored-by: Matthias Bussonnier <mbussonnier@ucmerced.edu> Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Renamed re.error for clarity, and kept re.error for backward compatibility. Updated idlelib files at TJR's request. --------- Co-authored-by: Matthias Bussonnier <mbussonnier@ucmerced.edu> Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: