Skip to content

Commit df989d1

Browse files
committed
Accept suggestions from new toolchain
1 parent a85b1fd commit df989d1

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

cfgs/__init__.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@
77
Fully compliant with the XDG Base Directory Specification.
88
"""
99

10-
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
1918

20-
File = Tuple[Union[Path, str]]
19+
File = tuple[Union[Path, str]]
2120
_NONE = object()
2221

2322

@@ -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
288287

289288
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
515514

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

520519
def create(self):
521520
"""Return new, empty contents"""
522-
return self._parser.SafeConfigParser()
521+
return self._parser.ConfigParser()
523522

524523
def as_dict(self, contents):
525524
"""Convert the contents to a dict"""

test/test_cfgs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import dataclasses as dc
2-
from cfgs import Configs
32
from typing import List
43

4+
from cfgs import Configs
5+
56

67
def field(factory):
78
return dc.field(default_factory=factory)
89

910

1011
@dc.dataclass
1112
class Audio(Configs):
12-
levels: List[float] = field(list)
13+
levels: list[float] = field(list)
1314

1415

1516
@dc.dataclass

test/test_dirs.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
from pyfakefs.fake_filesystem_unittest import TestCase as FakeTestCase
2-
import cfgs
31
import json
42
import platform
53

4+
from pyfakefs.fake_filesystem_unittest import TestCase as FakeTestCase
5+
6+
import cfgs
7+
68

79
class TestCase(FakeTestCase):
810
maxDiff = 2048
@@ -160,7 +162,7 @@ class CacheTest(TestCase):
160162
('five', '55555'),
161163
('six', '666666'),
162164
)
163-
EXPECTED = set(f for (f, c) in FILE_CONTENTS)
165+
EXPECTED = {f for (f, c) in FILE_CONTENTS}
164166

165167
def test_cache1(self):
166168
cache, listdir = self._create_cache(0, False)

0 commit comments

Comments
 (0)