Skip to content

Commit

Permalink
UserList to tell apart user set empty list from undefined value
Browse files Browse the repository at this point in the history
  • Loading branch information
TomekTrzeciak committed Dec 6, 2024
1 parent 4949998 commit 1d43c53
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 6 additions & 1 deletion cylc/flow/parsec/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def strip_and_unquote_list(cls, keys, value):
# allow trailing commas
if values[-1] == '':
values = values[0:-1]
return values
return UserList(values)

@classmethod
def _unquoted_list_parse(cls, keys, value):
Expand Down Expand Up @@ -647,6 +647,11 @@ def __str__(self):
return f'{self[0]} .. {self[1]}'


class UserList(list):
# used to distinguish user defined, possibly empty list from automatic defaults
pass


class CylcConfigValidator(ParsecValidator):
"""Type validator and coercer for Cylc configurations.
Expand Down
3 changes: 2 additions & 1 deletion cylc/flow/workflow_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from cylc.flow.cfgspec.glbl_cfg import glbl_cfg
from cylc.flow.hostuserutil import get_host, get_user
from cylc.flow.log_diagnosis import run_reftest
from cylc.flow.parsec.validate import UserList
from cylc.flow.subprocctx import SubProcContext

if TYPE_CHECKING:
Expand Down Expand Up @@ -235,7 +236,7 @@ def get_events_conf(
glbl_cfg().get(['scheduler', 'mail'])
):
value = getter.get(key)
if value is not None:
if value is not None and value != [] or isinstance(value, UserList):
return value
return default

Expand Down
9 changes: 5 additions & 4 deletions tests/unit/test_workflow_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import pytest

from collections import UserList
from types import SimpleNamespace

from cylc.flow.workflow_events import (
Expand All @@ -32,11 +33,11 @@
'key, workflow_cfg, glbl_cfg, expected',
[
('handlers', True, True, ['stall']),
('handlers', False, True, []),
('handlers', False, False, []),
('handlers', False, True, None),
('handlers', False, False, None),
('mail events', True, True, []),
('mail events', False, True, ['abort']),
('mail events', False, False, []),
('mail events', False, False, None),
('from', True, True, 'docklands@railway'),
('from', False, True, 'highway@mixture'),
('from', False, False, None),
Expand Down Expand Up @@ -65,7 +66,7 @@ def test_get_events_handler(
config = SimpleNamespace()
config.cfg = {
'scheduler': {
'events': {'handlers': ['stall'], 'mail events': []},
'events': {'handlers': ['stall'], 'mail events': UserList()},
'mail': {'from': 'docklands@railway'},
} if workflow_cfg else {'events': {}}
}
Expand Down

0 comments on commit 1d43c53

Please sign in to comment.