This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2010年11月21日 12:30 by lukasz.langa, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| issue10489.diff | lukasz.langa, 2010年11月21日 13:06 | Patch for removal of the broken `__name__` key | ||
| Messages (4) | |||
|---|---|---|---|
| msg121912 - (view) | Author: Łukasz Langa (lukasz.langa) * (Python committer) | Date: 2010年11月21日 12:30 | |
I want to sum up all strange things about the behaviour of `__name__`, a special key present in every section of a parser instance.
1. There is a special `__name__` key in every section.
2. Except for the DEFAULTSECT.
3. `__name__` key is set for every section read from a file.
4. and not when adding by `add_section()`.
5. if `__name__` does exist, it's not visible in `parser.options('section')`
6. but it is visible here: `parser.has_option('section', '__name__') == True`
7. and can be obtained by `parser.get('section', '__name__')`
8. and can be changed by `parser.set('section', '__name__', 'ANY VALUE')`
9. and can be removed by `parser.remove_option('section', '__name__')`
10. even if the value is changed by `parser.set()`, it won't be written back to a file with `parser.write()`
All this looks like a feature that was not particularly complete and well defined when it was first created. Or possibly, it became rotten with time and now nobody is using it anyway. That way or the other, I couldn't come up with a valid use case for `__name__` with the current implementation. It doesn't serve any internal purpose and the *only* way you can actually get it is to `parser.get('section', '__name__')` which returns 'section' anyway. About as useless as it gets. Of course, one can go and take the internal parser._sections data structure of the parser but that's evil.
I want simply remove all mentions of a special `__name__` key in configparser.py. Backwards compatibility is not a concern here because in this case we have a concept that is so broken that you can't actually use it.
|
|||
| msg121913 - (view) | Author: Łukasz Langa (lukasz.langa) * (Python committer) | Date: 2010年11月21日 12:33 | |
For the record, I wrote about this problem in July on the mailing list [1], there were no replies. [1] http://mail.python.org/pipermail/python-dev/2010-July/102556.html |
|||
| msg121920 - (view) | Author: Łukasz Langa (lukasz.langa) * (Python committer) | Date: 2010年11月21日 13:06 | |
Patch for the cleanup attached. 47 lines removed, about a half of these were in tests explicitly made to check for these inconsistencies. 4 lines added, all of them are reformattings due to removal of the other lines. Syntax highlighted view of the patch: http://bpaste.net/show/11395/ |
|||
| msg121928 - (view) | Author: Łukasz Langa (lukasz.langa) * (Python committer) | Date: 2010年11月21日 14:00 | |
Committed in rev 86638. A public API for getting the name of the section from a SectionProxy instance was introduced in 86639. This is useful because you can assing a section proxy to a variable and pass it around: >>> from configparser import SafeConfigParser >>> parser = SafeConfigParser() >>> parser.read_string(""" ... [section1] ... value = A ... value2 = B ... ... [section2] ... value = C ... value2 = D ... """) >>> section1 = parser['section1'] >>> section1['value'] 'A' >>> section1.name 'section1' >>> section2 = parser['section2'] >>> section2['value'] 'C' >>> section2.name 'section2' >>> section2.name = 'cannot do that, this attribute is read-only on a SectionProxy' Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: can't set attribute |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:09 | admin | set | github: 54698 |
| 2010年11月21日 14:00:34 | lukasz.langa | set | status: open -> closed resolution: accepted messages: + msg121928 stage: resolved |
| 2010年11月21日 13:06:53 | lukasz.langa | set | files:
+ issue10489.diff keywords: + patch messages: + msg121920 |
| 2010年11月21日 12:33:16 | lukasz.langa | set | messages: + msg121913 |
| 2010年11月21日 12:31:17 | lukasz.langa | set | nosy:
+ fdrake, georg.brandl, eric.araujo, michael.foord |
| 2010年11月21日 12:30:53 | lukasz.langa | create | |