Skip to content

Emphasising in the docs configparser.SafeConfigParser over ConfigParser #50766

Closed

Description

@till
mannequin
BPO 6517
Nosy @freddrake, @birkenfeld, @rhettinger, @merwok, @bitdancer, @voidspace, @ambv
Superseder
  • bpo-10499: Modular interpolation in configparser
  • Files
  • test-configparse.py: testcase
  • issue6517.patch
  • 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 = 'https://github.com/ambv'
    closed_at = <Date 2010-11-22.03:18:56.272>
    created_at = <Date 2009-07-18.20:36:38.767>
    labels = ['type-bug', 'docs']
    title = 'Emphasising in the docs configparser.SafeConfigParser over ConfigParser'
    updated_at = <Date 2010-11-22.03:18:56.271>
    user = 'https://bugs.python.org/till'

    bugs.python.org fields:

    activity = <Date 2010-11-22.03:18:56.271>
    actor = 'lukasz.langa'
    assignee = 'lukasz.langa'
    closed = True
    closed_date = <Date 2010-11-22.03:18:56.272>
    closer = 'lukasz.langa'
    components = ['Documentation']
    creation = <Date 2009-07-18.20:36:38.767>
    creator = 'till'
    dependencies = []
    files = ['14522', '14523']
    hgrepos = []
    issue_num = 6517
    keywords = ['patch']
    message_count = 33.0
    messages = ['90689', '90693', '90694', '90695', '90696', '111411', '111424', '111430', '111472', '111617', '111620', '111628', '111637', '112571', '112573', '112574', '112575', '112580', '112581', '112586', '112589', '112590', '112593', '112598', '112599', '112601', '112602', '112606', '112618', '112619', '112638', '112643', '122079']
    nosy_count = 8.0
    nosy_names = ['fdrake', 'georg.brandl', 'rhettinger', 'eric.araujo', 'r.david.murray', 'michael.foord', 'till', 'lukasz.langa']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'patch review'
    status = 'closed'
    superseder = '10499'
    type = 'behavior'
    url = 'https://bugs.python.org/issue6517'
    versions = ['Python 3.2']

    Activity

    1. till commented on Jul 18, 2009

      tillmannequin
      MannequinAuthor

      There seems to be no way to add a config item with a value containing a
      formatstring without this formatstring beeing handled by configparser.

      A possible way to escape the formatstrings could be to double the
      %-sign, e.g.:

      [foo]
      bar = %%(string)s

      The value of the bar item should then be "%(string)s".

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Jul 18, 2009
    3. bitdancer commented on Jul 18, 2009

      @bitdancer
      Member

      The formatstring is a Python % formatting code, and doubling the %% is
      the way to escape one, so what you suggest is in fact the way it works.
      Do you have a test case demonstrating that it doesn't work as
      documented (it works for me)?

    4. till commented on Jul 18, 2009

      tillmannequin
      MannequinAuthor

      Afacs it is not documented to work. Here is the testcase:

      #!/usr/bin/python
      # vim: fileencoding=utf8

      import ConfigParser
      import tempfile
      
      file = tempfile.TemporaryFile(mode='rw+b')
      file.write("[s]\nf=%%(b)s\n")
      file.seek(0)
      config = ConfigParser.ConfigParser()
      
      config.readfp(file)

      print config.get("s", "f")

      file.close()
    5. bitdancer commented on Jul 18, 2009

      @bitdancer
      Member

      Ah, that's because you aren't using SafeConfigParser (which the docs
      recommend that you do unless you have to use ConfigParser for backward
      compatibility reasons). Your test case works with SafeConfigParser.

      You are correct that it is not explicitly documented in the ConfigParser
      docs. It is implied by the fact that the magic substitution is
      documented to be a standard format string, and by the recommendation to
      use SafeConfigParser because ConfigParser's handling of formatstrings is
      broken.

      To make this all explicit, I've attached a doc patch to make the
      motivation for using SafeConfigParser clearer, using this as the
      example. Let me know what you think.

      Georg, Raymond, I added you as nosy to ask for a style/content opinion.
      Should we instead rewrite the section to put SafeConfigParser first,
      and perhaps even deprecate ConfigParser?

    6. added
      docsDocumentation in the Doc dir
      and removed
      stdlibStandard Library Python modules in the Lib/ directory
      on Jul 18, 2009
    7. self-assigned this
      on Jul 18, 2009
    8. till commented on Jul 18, 2009

      tillmannequin
      MannequinAuthor

      It would be nice if you could expand the patch to also use only one name
      for the support of format strings.

      In the beginning it is introduced as "reference expansion", but later in
      the document, several variatons of interpolation are used: "magical
      interpolation", "string interpolation", "%" interpolation is used.
      Therefore I guess it should also be introduced as interpolation.

      Another nice improvement would also be to move the ConfigParser to a
      "deprecated classes" section at the end like it is done for some methods
      in the string module.

    9. ambv commented on Jul 24, 2010

      @ambv
      Contributor

      This issue superseeds bpo-8888 because of the patches attached.

      Brett, there are two ways we can solve this issue:

      1. Rewrite the documentation so it clearly puts more emphasis on the fact that SafeConfigParser is the one to choose.
      2. We deprecate ConfigParser in the code and in the documentation.

      I personally would go with 1. and maybe just "hint" about the fact that ConfigParser is not for end users. Formal deprecation seems too big for this since the regular ConfigParser still does have its valid use cases.

      Please decide on what we're going to do and I'll edit the docs and add the tests here to py3k.

    10. freddrake commented on Jul 24, 2010

      @freddrake
      Member

      I disagree.

      The documentation should promote RawConfigParser, and note
      SafeConfigParser and ConfigParser as remaining for backward
      compatibility for existing software. Maintainers of legacy software
      using ConfigParser should be encouraged to convert to SafeConfigParser
      (or even RawConfigParser) if possible.

      Documentation changes should be sufficient; deprecation warnings
      typically generate more pain than good.

    11. ambv commented on Jul 24, 2010

      @ambv
      Contributor

      The documentation should promote RawConfigParser, and note
      SafeConfigParser and ConfigParser as remaining for backward
      compatibility for existing software.

      That is another way to go around this. Anyway, ConfigParser is the least predictable of all three for end users and the documentation should be adjusted to emphasize this.

      Maintainers of legacy software
      using ConfigParser should be encouraged to convert to SafeConfigParser
      (or even RawConfigParser) if possible.

      That's another comment that should appear in the documentation.

      Documentation changes should be sufficient; deprecation warnings
      typically generate more pain than good.

      Isn't is what I was saying above?

    12. freddrake commented on Jul 24, 2010

      @freddrake
      Member

      We're in agreement; I was specifically adding weight to *not*
      selecting the second optoin Łukasz Langa presented:

      1. We deprecate ConfigParser in the code and in the documentation.
    13. voidspace commented on Jul 26, 2010

      @voidspace
      Contributor

      This should just be applied. I'll do it shortly unless there is an objection.

    14. 13 remaining items

    15. freddrake commented on Aug 3, 2010

      @freddrake
      Member

      2010/8/3 Łukasz Langa <[email protected]>:

      1. In 3.2 we add an alias:

      InterpolatingConfigParser = SafeConfigParser

      I'd rather see the class renamed and SafeConfigParser made the alias in 3.2.

      Otherwise, +1 for this plan (msg 112589), as there's no silent breakage.

    16. voidspace commented on Aug 3, 2010

      @voidspace
      Contributor

      I'd be happy with aliasing SafeConfigParser to ConfigParser in 3.2. Can we just do this without a deprecation process?

    17. freddrake commented on Aug 3, 2010

      @freddrake
      Member

      Making ConfigParser an alias for SafeConfigParser creates a silent
      behavioral change. An application developer may not realize that
      users rely on the "full" ConfigParser anti-glory and end up breaking
      their configurations without so much as providing a heads-up in the
      application news.

      -1

      So long as the application developer has to change their code to move
      away from ConfigParser, there's a better chance of affected end users
      receiving a heads-up.

    18. ambv commented on Aug 3, 2010

      @ambv
      Contributor

      Unfortunately, I have to agree with Fred here. We'll stick to renaming and the deprecation process.

    19. voidspace commented on Aug 3, 2010

      @voidspace
      Contributor

      Sorry - I misunderstood your earlier suggestion Fred.

      configparser.ConfigParser is the *natural* name for SafeConfigParser. I'm strongly +1 on moving towards that. (I doubt there would *actually* be any real code breakage if we did it earlier though ;-)

    20. voidspace commented on Aug 3, 2010

      @voidspace
      Contributor

      By the way, given that deprecation warnings are silent I am strongly -1 on removing the ConfigParser name altogether. That would cause far more breakage. As ConfigParser should not be used at all, and SafeConfigParser provides its functionality minus bugs, SafeConfigParser (horrible name) should replace it.

    21. merwok commented on Aug 3, 2010

      @merwok
      Member

      Agree on the proposal of Łukasz, with the caveat mentioned by Fred (rename the class and make the old name an alias, for pickle and all). I’ll let Michael and Fred decide if the name ConfigParser has to go or not, I’m happy enough that the class will be deprecated and removed.

    22. voidspace commented on Aug 3, 2010

      @voidspace
      Contributor

      Getting *rid* of the name ConfigParser would be annoying and cause *gratuitous* code breakage.

      If we are going to keep the name but get rid of the "unsafe" version then we can only replace it with what is now SafeConfigParser - as it is almost entirely compatible with it. (Modulo the bug fixing "behavioural change".)

      So the real choices are:

      • leave ConfigParser as it is
      • deprecate it but not remove it (so as not to needlessly break code)
      • deprecate now and replace with SafeConfigParser later

      Only the last of these is a positive step forwards... :-)

      (Strongly -1 on introducing *yet another name* to refer to these classes by.)

    23. ambv commented on Aug 3, 2010

      @ambv
      Contributor

      There IS one more option that seems to be better than all of the above:

      1. Add an interpolation=True argument to RawConfigParser __init__ and move the interpolating functionality from SafeConfigParser to it.
      2. Rename RawConfigParser to ConfigParser leaving the old name in PendingDeprecation with interpolation=False.
      3. Make an alias for SafeConfigParser pointing to ConfigParser with PendingDeprecation.

      We can do all this for 3.2 I guess without inflicting any actual damage. It will fix more bugs in running code that break config files.

      Maybe we shouldn't be so afraid after all and just clean it up.

    24. freddrake commented on Aug 3, 2010

      @freddrake
      Member

      It doesn't make sense to make any of these changes to Python 2; this
      really should have been separate from the documentation issue. That's
      probably understood by everyone, but explicit is better.

      Merging implementations
      -----------------------

      • I've no objection to merging RawConfigParser and SafeConfigParser,
        using a constructor argument to control whether interpolation is
        performed. It's not clear this provides any improvement in
        maintainability or usage.

      • Isolating the old (broken interpolation) ConfigParser behavior so it's
        not in the middle of the inheritance stack would be good.

      Changing ConfigParser behavior
      ------------------------------

      Changing the behavior of the ConfigParser name requires the deprecation
      process. We may think nobody in their right mind is using that, but
      changing something out from under app developers is really bad. This
      should be considered a problem for configparser as outlined in msg 112598.

      Whether we can assign new semantics to the ConfigParser name in the
      future is questionable. I think Python's compatibility policy allows
      it, but that doesn't make it a good idea.

      (This seems to be the real sticking point, unfortunately.)

      Class names
      -----------

      I don't understand Michael's objection to adding new names for the
      configparser classes; that's one of the few points where we don't run
      into backward-compatibility black holes.

      In the case of a merged implementation, a new name for the merged class
      (possibly "Configuration") may be the best bet; the old names can then
      be subclasses of that which generate appropriate deprecation warnings.

    25. voidspace commented on Aug 3, 2010

      @voidspace
      Contributor

      If we merge the functionality in a single class with a new name then I guess that is fine as it will simplify the documentation rather than complexify it (good word hey). We still need to *mention* the old names so that people finding them in old code can find an up to date reference on them.

      Here's what I don't understand about Fred's difficulty with replacing ConfigParser with the sane implementation.

      After we deprecate ConfigParser as it is now we have two choices.

      • delete the ConfigParser name - breaking *all* code that uses it and has not been updated
      • point the name at what is currently called SafeConfigParser - causing a slight risk of incompatibility but likely *improving* most code that hasn't been updated

      I don't see how the first option could *in any way* be preferable to the second.

    26. self-assigned this
      on Aug 8, 2010
    27. ambv commented on Nov 22, 2010

      @ambv
      Contributor

      Hopefully both RawConfigParser and ConfigParser will be successfully deprecated as part of bpo-10499. The discussion goes on there.

    28. 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

    Labels

    docsDocumentation in the Doc dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions