Accept suggestions from new toolchain · rec/cfgs@df989d1

@@ -7,17 +7,16 @@

77

Fully compliant with the XDG Base Directory Specification.

88

"""

9910-

from enum import Enum

11-

from pathlib import Path

12-

from typing import Any, Dict, Optional, Tuple, Union

1310

import copy

1411

import dataclasses as dc

1512

import json

1613

import os

17-

import os

1814

import sys

15+

from enum import Enum

16+

from pathlib import Path

17+

from typing import Any, Dict, Optional, Tuple, Union

191820-

File = Tuple[Union[Path, str]]

19+

File = tuple[Union[Path, str]]

2120

_NONE = object()

22212322

@@ -50,7 +49,7 @@ def load(self, *files: File):

5049

def load_from_environ(

5150

self,

5251

prefix: str,

53-

environ: Optional[Dict] = None,

52+

environ: dict | None = None,

5453

verbose: bool = True,

5554

):

5655

if environ is None:

@@ -268,7 +267,7 @@ def open(self, filename=None):

268267

if not filename:

269268

basename = os.path.basename(self.home)

270269

suffix = FORMAT_TO_SUFFIX[self.format.name]

271-

filename = '%s%s' % (basename, suffix)

270+

filename = '{}{}'.format(basename, suffix)

272271

elif filename.startswith('/'):

273272

filename = filename[1:]

274273

@@ -283,7 +282,7 @@ def all_files(self, filename):

283282

full_path = os.path.join(p, filename)

284283

try:

285284

yield open(full_path) and full_path

286-

except IOError:

285+

except OSError:

287286

pass

288287289288

def full_name(self, filename):

@@ -322,7 +321,7 @@ def read(self):

322321

try:

323322

with open(self.filename) as fp:

324323

self.contents = self.format.read(fp)

325-

except IOError:

324+

except OSError:

326325

self.contents = self.format.create()

327326

return self.contents

328327

@@ -510,7 +509,7 @@ def __init__(self):

510509

def read(self, fp):

511510

"""Read contents from an open file in this format"""

512511

contents = self.create()

513-

contents.readfp(fp)

512+

contents.read_file(fp)

514513

return contents

515514516515

def write(self, contents, fp):

@@ -519,7 +518,7 @@ def write(self, contents, fp):

519518520519

def create(self):

521520

"""Return new, empty contents"""

522-

return self._parser.SafeConfigParser()

521+

return self._parser.ConfigParser()

523522524523

def as_dict(self, contents):

525524

"""Convert the contents to a dict"""