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 a4d2d8f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions cylc/flow/parsec/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"""

from copy import copy
from collections import deque
from collections import deque, UserList
import re
import sys

Expand Down Expand Up @@ -178,7 +178,7 @@ def printcfg(cfg, level=0, indent=0, prefix='', none_str='',
key = "%s = " % key_i
if cfg_i is None:
value = none_str
elif isinstance(cfg_i, list):
elif isinstance(cfg_i, (list, UserList)):
value = listjoin(cfg_i, none_str)
elif "\n" in str(cfg_i) and key:
value = '"""\n'
Expand Down
4 changes: 2 additions & 2 deletions cylc/flow/parsec/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import re
import shlex
from collections import deque
from collections import deque, UserList
from textwrap import dedent
from typing import List, Dict, Any, Optional, Tuple

Expand Down 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
3 changes: 2 additions & 1 deletion cylc/flow/workflow_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Workflow event handler."""

from collections import UserList
from enum import Enum
import os
from shlex import quote
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 type(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 a4d2d8f

Please sign in to comment.