mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
bpo-29623: Make PathLike objects work with ConfigParser.read() (#242)
This commit is contained in:
parent
677ab995ce
commit
85b8d01c91
4 changed files with 31 additions and 8 deletions
|
@ -143,6 +143,7 @@ from collections import OrderedDict as _default_dict, ChainMap as _ChainMap
|
|||
import functools
|
||||
import io
|
||||
import itertools
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import warnings
|
||||
|
@ -687,7 +688,7 @@ class RawConfigParser(MutableMapping):
|
|||
|
||||
Return list of successfully read files.
|
||||
"""
|
||||
if isinstance(filenames, str):
|
||||
if isinstance(filenames, (str, os.PathLike)):
|
||||
filenames = [filenames]
|
||||
read_ok = []
|
||||
for filename in filenames:
|
||||
|
@ -696,6 +697,8 @@ class RawConfigParser(MutableMapping):
|
|||
self._read(fp, filename)
|
||||
except OSError:
|
||||
continue
|
||||
if isinstance(filename, os.PathLike):
|
||||
filename = os.fspath(filename)
|
||||
read_ok.append(filename)
|
||||
return read_ok
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue