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.

classification
Title: configparser - no support for cascading defaults (as defined by MySQL)
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9, Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Ben Griffin, python-dev
Priority: normal Keywords: patch

Created on 2020-03-05 09:07 by Ben Griffin, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 18791 open python-dev, 2020-03-05 10:48
Messages (3)
msg363421 - (view) Author: Ben Griffin (Ben Griffin) * Date: 2020-03-05 09:07
While there is now support for a single default group, mysql documentation is clear that there is a cascade of groups for option settings, normally starting with [client], and including version numbers..

This allows generic settings to be overridden by specific settings, and it's an important feature when building an architecture around a mysql/mariadb environment.

A typical configuration chain may look like this.

[client] -> [mysql] -> [mysql-5.6] -> [pymysql] -> [my_custom_app]

Currently, the implementation of configparser only allows the programmer to define the default group (typically [client]) and then the group to read from [my_custom_app].

In terms of a proposed approach to the library, I suggest two changes (both backwards compatible).
(1) Extend the 'default_section' initializer such that it supports both a string (current implementation) and an iterable (ordered from specialised to general).

(2) Likewise extend the 'section' parameter of get() such that it supports both a string (current implementation) and an iterable (ordered from specialised to general), as above.

Mysql's own docs are as follows.

https://dev.mysql.com/doc/refman/8.0/en/option-files.html#option-file-syntax

"List more general option groups first and more specific groups later. For example, a [client] group is more general because it is read by all client programs, whereas a [mysqldump] group is read only by mysqldump. Options specified later override options specified earlier, so putting the option groups in the order [client], [mysqldump] enables mysqldump-specific options to override [client] options."
msg363428 - (view) Author: Ben Griffin (Ben Griffin) * Date: 2020-03-05 11:11
Having looked at the code, I believe that it is best NOT to interfere with the 'default_section' value of the class, as it is used as a proxy to _defaults, whereas the section parameter of get() is easily extended.

The actual changes are all to the method _unify_values, and it is trivial to extend that method to allow for multiple dictionaries to be passed to _ChainMap.

This is what I did in PR-18791
msg412899 - (view) Author: Ben Griffin (Ben Griffin) * Date: 2022-02-09 12:09
This is still being ignored.  
It's a bug, because it prevents the ini file from being used by other clients.
History
Date User Action Args
2022-04-11 14:59:27adminsetgithub: 84041
2022-02-09 12:09:55Ben Griffinsetmessages: + msg412899
versions: + Python 3.8, Python 3.9, Python 3.10, Python 3.11
2020-03-05 11:11:19Ben Griffinsettype: enhancement
messages: + msg363428
2020-03-05 10:48:00python-devsetkeywords: + patch
nosy: + python-dev

pull_requests: + pull_request18148
stage: patch review
2020-03-05 09:07:57Ben Griffincreate