Skip to content

Commit 65b6268

Browse files
authored
Merge pull request SCons#4561 from mwichmann/variables-niggles
Minor cleanups in Variables
2 parents 268a942 + 6baf4d4 commit 65b6268

18 files changed

+60
-64
lines changed

SCons/Variables/BoolVariable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
__all__ = ['BoolVariable',]
4040

41-
TRUE_STRINGS = ('y', 'yes', 'true', 't', '1', 'on' , 'all')
41+
TRUE_STRINGS = ('y', 'yes', 'true', 't', '1', 'on', 'all')
4242
FALSE_STRINGS = ('n', 'no', 'false', 'f', '0', 'off', 'none')
4343

4444

@@ -66,7 +66,7 @@ def _text2bool(val: str) -> bool:
6666
def _validator(key, val, env) -> None:
6767
"""Validate that the value of *key* in *env* is a boolean.
6868
69-
Parmaeter *val* is not used in the check.
69+
Parameter *val* is not used in the check.
7070
7171
Usable as a validator function for SCons Variables.
7272

SCons/Variables/EnumVariable.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ def EnumVariable(
9191
map: optional dictionary which may be used for converting the
9292
input value into canonical values (e.g. for aliases).
9393
ignorecase: defines the behavior of the validator and converter.
94-
validator: callback function to test whether the value is in the
95-
list of allowed values.
96-
converter: callback function to convert input values according to
97-
the given *map*-dictionary. Unmapped input values are returned
98-
unchanged.
9994
10095
Returns:
10196
A tuple including an appropriate converter and validator.

SCons/Variables/EnumVariableTests.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ def test_converter(self) -> None:
9797
'c' : 'three'},
9898
ignorecase=2))
9999

100-
o0 = opts.options[0]
101-
o1 = opts.options[1]
102-
o2 = opts.options[2]
100+
opt0 = opts.options[0]
101+
opt1 = opts.options[1]
102+
opt2 = opts.options[2]
103103

104104
table = {
105105
'one' : ['one', 'one', 'one'],
@@ -119,13 +119,13 @@ def test_converter(self) -> None:
119119
'C' : ['C', 'three', 'three'],
120120
}
121121

122-
for k, l in table.items():
123-
x = o0.converter(k)
124-
assert x == l[0], f"o0 got {x}, expected {l[0]}"
125-
x = o1.converter(k)
126-
assert x == l[1], f"o1 got {x}, expected {l[1]}"
127-
x = o2.converter(k)
128-
assert x == l[2], f"o2 got {x}, expected {l[2]}"
122+
for k, expected in table.items():
123+
x = opt0.converter(k)
124+
assert x == expected[0], f"opt0 got {x}, expected {expected[0]}"
125+
x = opt1.converter(k)
126+
assert x == expected[1], f"opt1 got {x}, expected {expected[1]}"
127+
x = opt2.converter(k)
128+
assert x == expected[2], f"opt2 got {x}, expected {expected[2]}"
129129

130130
def test_validator(self) -> None:
131131
"""Test the EnumVariable validator"""
@@ -149,9 +149,9 @@ def test_validator(self) -> None:
149149
'c' : 'three'},
150150
ignorecase=2))
151151

152-
o0 = opts.options[0]
153-
o1 = opts.options[1]
154-
o2 = opts.options[2]
152+
opt0 = opts.options[0]
153+
opt1 = opts.options[1]
154+
opt2 = opts.options[2]
155155

156156
def valid(o, v) -> None:
157157
o.validator('X', v, {})
@@ -181,10 +181,10 @@ def invalid(o, v) -> None:
181181
'no_v' : [invalid, invalid, invalid],
182182
}
183183

184-
for v, l in table.items():
185-
l[0](o0, v)
186-
l[1](o1, v)
187-
l[2](o2, v)
184+
for v, expected in table.items():
185+
expected[0](opt0, v)
186+
expected[1](opt1, v)
187+
expected[2](opt2, v)
188188

189189

190190
if __name__ == "__main__":

SCons/Variables/ListVariable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def _validator(key, val, env) -> None:
140140
so we need to fish the allowed elements list out of the environment
141141
to complete the validation.
142142
143-
Note that since 18b45e456, whether or not ``subst`` has been
143+
Note that since 18b45e456, whether ``subst`` has been
144144
called is conditional on the value of the *subst* argument to
145145
:meth:`~SCons.Variables.Variables.Add`, so we have to account for
146146
possible different types of *val*.

SCons/Variables/ListVariableTests.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def test_converter(self) -> None:
112112
assert str(x) == 'no_match', x
113113
# ... and fail to validate
114114
with self.assertRaises(SCons.Errors.UserError):
115-
z = o.validator('test', 'no_match', {"test": x})
115+
o.validator('test', 'no_match', {"test": x})
116116

117117
def test_copy(self) -> None:
118118
"""Test copying a ListVariable like an Environment would"""
@@ -121,9 +121,8 @@ def test_copy(self) -> None:
121121
['one', 'two', 'three']))
122122

123123
o = opts.options[0]
124-
125-
l = o.converter('all')
126-
n = l.__class__(copy.copy(l))
124+
res = o.converter('all')
125+
_ = res.__class__(copy.copy(res))
127126

128127
if __name__ == "__main__":
129128
unittest.main()

SCons/Variables/PackageVariableTests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def test_validator(self) -> None:
101101
o.validator('T', '/path', env)
102102
o.validator('X', exists, env)
103103

104-
with self.assertRaises(SCons.Errors.UserError) as cm:
104+
with self.assertRaises(SCons.Errors.UserError):
105105
o.validator('X', does_not_exist, env)
106106

107107

SCons/Variables/PathVariable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def __call__(
161161
helpmsg = f'{help} ( /path/to/{key[0]} )'
162162
else:
163163
helpmsg = f'{help} ( /path/to/{key} )'
164-
return (key, helpmsg, default, validator, None)
164+
return key, helpmsg, default, validator, None
165165

166166

167167
PathVariable = _PathVariableClass()

SCons/Variables/PathVariableTests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class ValidatorError(Exception):
196196
pass
197197

198198
def my_validator(key, val, env):
199-
raise ValidatorError(f"my_validator() got called for {key!r}, {val}!")
199+
raise ValidatorError(f"my_validator() got called for {key!r}, {val!r}!")
200200

201201
opts = SCons.Variables.Variables()
202202
opts.Add(SCons.Variables.PathVariable('test2',
@@ -207,7 +207,7 @@ def my_validator(key, val, env):
207207
with self.assertRaises(ValidatorError) as cm:
208208
o.validator('Y', 'value', {})
209209
e = cm.exception
210-
self.assertEqual(str(e), f"my_validator() got called for 'Y', value!")
210+
self.assertEqual(str(e), "my_validator() got called for 'Y', 'value'!")
211211

212212

213213
if __name__ == "__main__":

SCons/Variables/VariablesTests.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ def conv_subst(value) -> None:
206206
lambda x: int(x) + 12)
207207

208208
env = Environment()
209-
exc_caught = None
210209
with self.assertRaises(AssertionError):
211210
opts.Update(env)
212211

@@ -375,8 +374,10 @@ def test_Save(self) -> None:
375374
opts = SCons.Variables.Variables()
376375

377376
def bool_converter(val):
378-
if val in [1, 'y']: val = 1
379-
if val in [0, 'n']: val = 0
377+
if val in [1, 'y']:
378+
val = 1
379+
if val in [0, 'n']:
380+
val = 0
380381
return val
381382

382383
# test saving out empty file

SCons/Variables/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434

3535
# Note: imports are for the benefit of SCons.Main (and tests); since they
3636
# are not used here, the "as Foo" form is for checkers.
37-
from .BoolVariable import BoolVariable as BoolVariable
38-
from .EnumVariable import EnumVariable as EnumVariable
39-
from .ListVariable import ListVariable as ListVariable
40-
from .PackageVariable import PackageVariable as PackageVariable
41-
from .PathVariable import PathVariable as PathVariable
37+
from .BoolVariable import BoolVariable
38+
from .EnumVariable import EnumVariable
39+
from .ListVariable import ListVariable
40+
from .PackageVariable import PackageVariable
41+
from .PathVariable import PathVariable
4242

4343
__all__ = [
4444
"Variable",

0 commit comments

Comments
 (0)