-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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 AttributeError: 'NoneType' object has no attribute 'append' #107625
Comments
Behavior verified with 3.12.0b4 on Win10. I agree that configparser has a bug. I also think that a continuation line for a no-value option is a user bug. So I would a line to the structure section saying so and raise a ParsingError with a message something like "No-value option {opname} cannot be continued". Line 1084, Adding |
- raise ParsingError instaed of AttributeError if a key contains empty value in a non recommended scenario where extra space and blankline is present within the section
I have added a PR as you suggested @terryjreedy |
…H-107651) Co-authored-by: Éric <merwok@netwok.org> Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Thank you for the fix! Since this only changes the error type (and message), I'll not backport. Let me know if you think I should. |
…inued (pythonGH-107651) Co-authored-by: Éric <merwok@netwok.org> Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
…inued (pythonGH-107651) Co-authored-by: Éric <merwok@netwok.org> Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Bug report
Checklist
A clear and concise description of the bug
When trying to parse an INI with an indented key that follows a no-value key, an AttributeError is raised
The reason is that ConfigParser assumes the second key is a continuation line and therefore further assumes that
cursect[optname]
is initialized in the following check:Suggested fix: add a check for
cursect[optname] is not None
:With this check added, the print will output:
If the suggested fix is not acceptable, please consider to add a check and maybe raise a
ParsingError
, but making an assumption aboutcursect[optname]
and let it raise an AttributeError is just not a good thing, IMHO.Your environment
Linked PRs
The text was updated successfully, but these errors were encountered: