Skip to content

ConfigParser.set does not convert non-string values #53126

Closed

Description

@EdwinPozharski
BPO 8880
Nosy @merwok, @bitdancer
Files
  • unnamed
  • 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:

    assignee = None
    closed_at = <Date 2010-06-02.21:33:17.443>
    created_at = <Date 2010-06-02.21:01:36.677>
    labels = ['type-bug', 'library']
    title = 'ConfigParser.set does not convert non-string values'
    updated_at = <Date 2010-06-03.13:37:51.855>
    user = 'https://bugs.python.org/EdwinPozharski'

    bugs.python.org fields:

    activity = <Date 2010-06-03.13:37:51.855>
    actor = 'Edwin.Pozharski'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-06-02.21:33:17.443>
    closer = 'r.david.murray'
    components = ['Library (Lib)']
    creation = <Date 2010-06-02.21:01:36.677>
    creator = 'Edwin.Pozharski'
    dependencies = []
    files = ['17531']
    hgrepos = []
    issue_num = 8880
    keywords = []
    message_count = 5.0
    messages = ['106912', '106913', '106918', '106944', '106950']
    nosy_count = 3.0
    nosy_names = ['eric.araujo', 'r.david.murray', 'Edwin.Pozharski']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue8880'
    versions = ['Python 3.2']

    Activity

    1. EdwinPozharski commented on Jun 2, 2010

      EdwinPozharskimannequin
      MannequinAuthor

      set() method of ConfigParser accepts boolean True/False as values at runtime without converting them to strings internally. As a result, getboolean() method reports the following error

      File "/usr/lib/python2.6/ConfigParser.py", line 350, in getboolean
      if v.lower() not in self._boolean_states:
      AttributeError: 'bool' object has no attribute 'lower'

      since it expects get() method to return strings. (Same problem occurs if other types are used, int/float, etc)

      Altering set() behavior may be not the best thing to do, I'd rather suggest that getboolean() converts the get() output to string.

      Of course, the way to avoid this problem is always convert values submitted to set() to strings, but it's a hard-to-catch bug. In my case, I was stuck with problematic configuration when assigning values to wx.CheckBox.GetValue(), which returns boolean.

    2. merwok commented on Jun 2, 2010

      @merwok
      Member

      Would that mean that booleans would be converted to strings on set and converted back on get? Seems wasteful.

      (I’ve changed the version field for this bug. Its meaning is not “versions this applies to” but “versions that will get a fix”, and 3.2 is the only active branch now. Some bugfixes may still go into 2.7.)

    3. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Jun 2, 2010
    4. bitdancer commented on Jun 2, 2010

      @bitdancer
      Member

      Use SafeConfigParser instead, then you can't make the mistake of passing non-strings to set.

      We really should update the docs so that ConfigParser is doced only in a 'deprecated' section. But that's a different issue. (Care to open it, merwok? :)

    5. merwok commented on Jun 3, 2010

      @merwok
      Member
    6. EdwinPozharski commented on Jun 3, 2010

      EdwinPozharskimannequin
      MannequinAuthor

      Thanks - gotta rtfm :)

      On Wed, Jun 2, 2010 at 5:33 PM, R. David Murray <[email protected]>wrote:

      R. David Murray <[email protected]> added the comment:

      Use SafeConfigParser instead, then you can't make the mistake of passing
      non-strings to set.

      We really should update the docs so that ConfigParser is doced only in a
      'deprecated' section. But that's a different issue. (Care to open it,
      merwok? :)

      ----------
      nosy: +r.david.murray
      resolution: -> wont fix
      stage: -> committed/rejected
      status: open -> closed


      Python tracker <[email protected]>
      <http://bugs.python.org/issue8880\>


    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions