Skip to content

Commit

Permalink
Style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarak committed Jul 3, 2023
1 parent 5454737 commit 5b0c6b5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
10 changes: 4 additions & 6 deletions reframe/utility/typecheck.py
Expand Up @@ -325,9 +325,9 @@ def __rfm_cast_str__(cls, s):
value_type = cls._value_type

try:
d = json.loads(s)
items = json.loads(s)
except json.JSONDecodeError:
seq = []
items = []
for key_datum in s.split(','):
try:
k, v = key_datum.split(':')
Expand All @@ -337,11 +337,9 @@ def __rfm_cast_str__(cls, s):
f'cannot convert string {s!r} to {cls.__name__!r}'
) from None

seq.append((key_type(k), value_type(v)))
items.append((key_type(k), value_type(v)))

return mappping_type(seq)
else:
return mappping_type(d)
return mappping_type(items)


class _StrType(_SequenceType):
Expand Down
12 changes: 6 additions & 6 deletions unittests/test_typecheck.py
Expand Up @@ -209,12 +209,12 @@ def test_mapping_type():
assert typ.Dict[str, int]('a:1,b:2') == {'a': 1, 'b': 2}

# Conversion with JSON syntax, for nested dictionaries
s = '{"gpu":{"num_gpus_per_node":8}, "mpi": {"num_slots": 64}}'
assert (typ.Dict[str, typ.Dict[str, object]](s) ==
{
"gpu": {"num_gpus_per_node": 8},
"mpi": {"num_slots": 64},
})
s = '{"gpu":{"num_gpus_per_node": 8}, "mpi": {"num_slots": 64}}'
expected = {
'gpu': {'num_gpus_per_node': 8},
'mpi': {'num_slots': 64},
}
assert typ.Dict[str, typ.Dict[str, object]](s) == expected

with pytest.raises(TypeError):
typ.Dict[str, int]('a:1,b')
Expand Down

0 comments on commit 5b0c6b5

Please sign in to comment.