-
-
Notifications
You must be signed in to change notification settings - Fork 29.1k
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
configparser: reading an invalid file triggers ParsingError *and* mutations #95546
Comments
# a non-fatal parsing error occurred. set up the
# exception but keep going. the exception will be
# raised at the end of the file and will contain a
# list of all bogus lines Apparently, the ParsingError is considered non-fatal so it continues. If you use: cfg.read_string('[foo]\nx = 1\n...\ny = 2')
I don't feel raising the error after the fact makes much sense either but it is done with the idea that you are shown all the lines that are wrong instead of having to run the config as many times are there are errors. |
Furthermore, if you catch
Reproduced with Python 3.10 and 3.12. P.S. Disabling interpolation can read the value from the 1st section but it's a list, not a str:
|
The behaviour in my previous comment is because Lines 1059 to 1062 in 43c9d61
Maybe this should go in a |
I have raised #116957 for the bug I described in my 2 previous comments, which is about Duplicate{Section,Option}Error rather than ParsingError. |
Bug report
A clear and concise description of what the bug is.
Include a minimal, reproducible example (https://stackoverflow.com/help/minimal-reproducible-example), if possible.
Your environment
here is a simple example:
I expect reading to be an all-or-nothing operation -- if the file contains a syntax error it shouldn't modify the
ConfigParser
object with half of the file's contentsThe text was updated successfully, but these errors were encountered: