-
-
Notifications
You must be signed in to change notification settings - Fork 29.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
ConfigParser does not handle options without values #51254
Comments
When ConfigParser is used to read in a my.cnf file (MySQL Server ConfigParser is designed to require a value for each option, but some There is an attached patch that optionally will allow options to not The default behavior is to not allow options without values. |
The test "value is not None" in line 620 (of the new version) could be I don't think I've ever run across a sample .ini-style file that used Have you come across an existing configuration format that uses the |
I replied to the mail, but I don't know if it is attached to the issue, I'll change the "value is not None" to just "value" where I used that idiom. The style of using options without values is quite common in my.cnf |
Fred L. Drake, Jr. wrote:
OK.
It is very common in my.cnf files for MySQL, and has been so "for ever." For Best wishes,
|
Adding patch with the changes requested by Fred. |
I just looked at some MySQL configuration examples, and wonder if the MySQL's syntax is sufficient justification for this feature (however (I've not read the patch.) |
So, what is the status on this? |
Assigning to myself for handling. Bumping to Python 2.7 / 3.2 since support for this syntax variation is a new feature. |
Patch and documentation committed to the trunk (r78232). |
Patch and documentation merged to the py3k branch (r78233). Work on this is complete. |
This is causing a regression in our code. Previously when we write out our INI file for an entry that has a value of None we saw the following: These are now stored as: This is now causing a traceback in our code. But interestingly I haven't changed anything in our initialisation of ConfigParser, I would have assumed that I need to set allow_no_value for this to work in the new way that MySQL expects. I would have expected everything to work as it currently does in 2.6 unless I specifically request You can see the traceback of Virtaal under Python 2. in this bug: |
Re-opening for investigation. (The previous message really should have been a new issue.) |
This one is strange. Trying to set a None value through set() raises 'TypeError: option values must be strings' on both Python 3.2 and 2.7. A string value of 'None' behaves as expected (e.g. correctly). |
I've attached a diagnostic script that I ran with Python 2.4..3.2 (current py3k HEAD); there are two output variants: "old style":
"new style":
This is the output I get when running this script for each of those Python versions:
Essentially: For the RawConfigParser and ConfigParser classes, the output changes in 2.7 and 3.2, and in a way that should be considered incorrect because it conflicts with the allow_no_values setting. This is a bug and should be fixed in both 2.7 and 3.2. The TypeError-on-set is consistently raised only for SafeConfigParser, and should remain unchanged. (Why this was handled differently for SafeConfigParser I don't recall offhand.) |
Attached fix & test for Python 2; adjusting to Python 3 is trivial. The test could be added to 2.6 as well to protect against regressions there, though that's unlikely to be a significant issue. |
Commited as r84443 (release27-maint), r84444 (py3k) |
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:
The text was updated successfully, but these errors were encountered: