Skip to content
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.read silently fails if filenames argument is a byte string #75488

Closed
vxgmichel mannequin opened this issue Aug 30, 2017 · 5 comments
Closed

ConfigParser.read silently fails if filenames argument is a byte string #75488

vxgmichel mannequin opened this issue Aug 30, 2017 · 5 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@vxgmichel
Copy link
Mannequin

vxgmichel mannequin commented Aug 30, 2017

BPO 31307
Nosy @ambv, @berkerpeksag, @vxgmichel, @DavidCEllis, @cryvate
PRs
  • bpo-31307: Allow use of bytes object as a single argument in ConfigParser.read #3420
  • 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 2017-11-02.12:49:05.393>
    created_at = <Date 2017-08-30.14:15:47.010>
    labels = ['3.7', 'type-feature', 'library']
    title = 'ConfigParser.read silently fails if filenames argument is a byte string'
    updated_at = <Date 2017-11-02.12:49:05.391>
    user = 'https://github.com/vxgmichel'

    bugs.python.org fields:

    activity = <Date 2017-11-02.12:49:05.391>
    actor = 'berker.peksag'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-11-02.12:49:05.393>
    closer = 'berker.peksag'
    components = ['Library (Lib)']
    creation = <Date 2017-08-30.14:15:47.010>
    creator = 'vxgmichel'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31307
    keywords = []
    message_count = 5.0
    messages = ['301026', '301149', '301192', '305421', '305422']
    nosy_count = 5.0
    nosy_names = ['lukasz.langa', 'berker.peksag', 'vxgmichel', 'David Ellis', 'cryvate']
    pr_nums = ['3420']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue31307'
    versions = ['Python 3.7']

    @vxgmichel
    Copy link
    Mannequin Author

    vxgmichel mannequin commented Aug 30, 2017

    Calling config_parser.read with 'test' is equivalent to:

        config_parser.read(['test'])
    
    while calling `config_parser.read` with `b'test'` is treated as:
    
        config_parser.read([116, 101, 115, 116])

    which means python will try to open the file descriptors 101, 115 and 116.

    I don't know if byte path should be supported, but this is probably not the expected behavior.

    The method code: https://github.com/python/cpython/blob/master/Lib/configparser.py#L678-L702

    @vxgmichel vxgmichel mannequin added type-bug An unexpected behavior, bug, or error 3.7 (EOL) end of life stdlib Python modules in the Lib dir labels Aug 30, 2017
    @ambv
    Copy link
    Contributor

    ambv commented Sep 1, 2017

    Good catch. Supporting bytes passed as a path is a reasonable request since the builtin open() supports this, too. Go ahead and create a pull request! We only need to modify line 690 to also list bytes.

    @DavidCEllis
    Copy link
    Mannequin

    DavidCEllis mannequin commented Sep 3, 2017

    This is related to the issue I'd brought up previously here so closing this would also close that issue: http://bugs.python.org/issue29627

    I did originally attempt to add support for bytes in PR where I added support for Path-like objects:
    #242 but I was asked to take it back out.

    @berkerpeksag
    Copy link
    Member

    New changeset e314853 by Berker Peksag (Vincent Michel) in branch 'master':
    bpo-31307: Make ConfigParser.read() accept bytes objects (GH-3420)
    e314853

    @berkerpeksag
    Copy link
    Member

    Thanks! I went ahead and merged PR 3420 since Łukasz (the configparser maintainer) has accepted the idea.

    @berkerpeksag berkerpeksag added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Nov 2, 2017
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants