Skip to content

Commit 5112c8a

Browse files
committed
Fix some issues reported by ruff
1 parent 9575b23 commit 5112c8a

6 files changed

Lines changed: 23 additions & 23 deletions

File tree

setup_validate.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# This software is licensed under the terms of the BSD license.
1212
# http://opensource.org/licenses/BSD-3-Clause
1313

14-
import sys
1514
from distutils.core import setup
1615
from validate import __version__ as VERSION
1716

src/configobj/__init__.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def __init__(self, section):
297297

298298
def interpolate(self, key, value):
299299
# short-cut
300-
if not self._cookie in value:
300+
if self._cookie not in value:
301301
return value
302302

303303
def recursive_interpolate(key, value, section, backtrail):
@@ -528,7 +528,7 @@ def _interpolate(self, key, value):
528528
except AttributeError:
529529
# not yet: first time running _interpolate(), so pick the engine
530530
name = self.main.interpolation
531-
if name == True: # note that "if name:" would be incorrect here
531+
if name is True: # note that "if name:" would be incorrect here
532532
# backwards-compatibility: interpolation=True means use default
533533
name = DEFAULT_INTERPOLATION
534534
name = name.lower() # so that "Template", "template", etc. all work
@@ -948,9 +948,9 @@ def as_bool(self, key):
948948
0
949949
"""
950950
val = self[key]
951-
if val == True:
951+
if val is True:
952952
return True
953-
elif val == False:
953+
elif val is False:
954954
return False
955955
else:
956956
try:
@@ -2237,7 +2237,7 @@ def validate_entry(entry, spec, val, missing, ret_true, ret_false):
22372237
if entry in ('__many__', '___many___'):
22382238
# reserved names
22392239
continue
2240-
if (not entry in section.scalars) or (entry in section.defaults):
2240+
if (entry not in section.scalars) or (entry in section.defaults):
22412241
# missing entries
22422242
# or entries from defaults
22432243
missing = True
@@ -2300,9 +2300,9 @@ def validate_entry(entry, spec, val, missing, ret_true, ret_false):
23002300
section.inline_comments[entry] = configspec.inline_comments.get(entry, '')
23012301
check = self.validate(validator, preserve_errors=preserve_errors, copy=copy, section=section[entry])
23022302
out[entry] = check
2303-
if check == False:
2303+
if check is False:
23042304
ret_true = False
2305-
elif check == True:
2305+
elif check is True:
23062306
ret_false = False
23072307
else:
23082308
ret_true = False
@@ -2421,15 +2421,15 @@ def flatten_errors(cfg, res, levels=None, results=None):
24212421
# first time called
24222422
levels = []
24232423
results = []
2424-
if res == True:
2424+
if res is True:
24252425
return sorted(results)
2426-
if res == False or isinstance(res, Exception):
2426+
if res is False or isinstance(res, Exception):
24272427
results.append((levels[:], None, res))
24282428
if levels:
24292429
levels.pop()
24302430
return sorted(results)
24312431
for (key, val) in list(res.items()):
2432-
if val == True:
2432+
if val is True:
24332433
continue
24342434
if isinstance(cfg.get(key), dict):
24352435
# Go down one level

src/configobj/validate.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@
163163

164164
import re
165165
import sys
166-
from pprint import pprint
167166

168167

169168
_list_arg = re.compile(r'''
@@ -264,7 +263,8 @@ def dottedQuadToNum(ip):
264263
"""
265264

266265
# import here to avoid it when ip_addr values are not used
267-
import socket, struct
266+
import socket
267+
import struct
268268

269269
try:
270270
return struct.unpack('!L',
@@ -314,7 +314,8 @@ def numToDottedQuad(num):
314314
"""
315315

316316
# import here to avoid it when ip_addr values are not used
317-
import socket, struct
317+
import socket
318+
import struct
318319

319320
# no need to intercept here, 4294967295L is fine
320321
if num > int(4294967295) or num < 0:
@@ -653,7 +654,7 @@ def _parse_check(self, check):
653654
keymatch = self._key_arg.match(arg)
654655
if keymatch:
655656
val = keymatch.group(2)
656-
if not val in ("'None'", '"None"'):
657+
if val not in ("'None'", '"None"'):
657658
# Special case a quoted None
658659
val = self._unquote(val)
659660
fun_kwargs[keymatch.group(1)] = val
@@ -740,7 +741,7 @@ def _is_num_param(names, values, to_float=False):
740741
elif isinstance(val, (int, float, str)):
741742
try:
742743
out_params.append(fun(val))
743-
except ValueError as e:
744+
except ValueError:
744745
raise VdtParamError(name, val)
745746
else:
746747
raise VdtParamError(name, val)
@@ -919,9 +920,9 @@ def is_boolean(value):
919920
# we do an equality test rather than an identity test
920921
# this ensures Python 2.2 compatibilty
921922
# and allows 0 and 1 to represent True and False
922-
if value == False:
923+
if value is False:
923924
return False
924-
elif value == True:
925+
elif value is True:
925926
return True
926927
else:
927928
raise VdtTypeError(value)
@@ -1301,7 +1302,7 @@ def is_option(value, *options):
13011302
"""
13021303
if not isinstance(value, str):
13031304
raise VdtTypeError(value)
1304-
if not value in options:
1305+
if value not in options:
13051306
raise VdtValueError(value)
13061307
return value
13071308

src/tests/test_configobj.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def test_unicode_handling():
508508
file_like.seek(0)
509509
uc2 = ConfigObj(file_like)
510510
assert uc2 == uc
511-
assert uc2.filename == None
511+
assert uc2.filename is None
512512
assert uc2.newlines == '\r'
513513

514514

src/tests/test_validate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from configobj import ConfigObj
44
import pytest
5-
from configobj.validate import Validator, VdtValueTooSmallError
5+
from configobj.validate import VdtValueTooSmallError
66

77

88
class TestImporting(object):

src/tests/test_validate_errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ def test_invalid_lines_with_percents(tmpdir, specpath):
6969
ini = tmpdir.join('config.ini')
7070
ini.write('extra: %H:%M\n')
7171
with pytest.raises(ParseError):
72-
conf = ConfigObj(str(ini), configspec=specpath, file_error=True)
72+
ConfigObj(str(ini), configspec=specpath, file_error=True)
7373

7474

7575
def test_no_parent(tmpdir, specpath):
7676
ini = tmpdir.join('config.ini')
7777
ini.write('[[haha]]')
7878
with pytest.raises(NestingError):
79-
conf = ConfigObj(str(ini), configspec=specpath, file_error=True)
79+
ConfigObj(str(ini), configspec=specpath, file_error=True)
8080

8181

8282
def test_re_dos(val):

0 commit comments

Comments
 (0)