Modify ↓
Opened 9 years ago
Closed 9 years ago
#12770 closed enhancement (fixed)
to_list should return empty list on falsy input
| Reported by: | Ryan J Ollos | Owned by: | Ryan J Ollos |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.2.2 |
| Component: | general | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Branch: | ||
| Release Notes: | |||
| API Changes: |
|
||
| Internal Changes: | |||
Description
It would be nice if to_list returned an empty list on falsy input, so that short statements like to_list(req.args.get('key')) could be used without altering the default arg of None.
-
trac/util/__init__.py
diff --git a/trac/util/__init__.py b/trac/util/__init__.py index 6135f2f3d..1e7a6f20d 100644
a b def pathjoin(*args): 1307 1307 def to_list(splittable, sep=','): 1308 1308 """Split a string at `sep` and return a list without any empty items. 1309 1309 """ 1310 if not splittable: 1311 return [] 1310 1312 split = [x.strip() for x in splittable.split(sep)] 1311 1313 return [item for item in split if item]
>>> from trac.util import to_list >>> to_list([]) [] >>> to_list(None) [] >>> to_list('') []
Attachments (0)
Change History (1)
comment:1 by , 9 years ago
| API Changes: | modified (diff) |
|---|---|
| Resolution: | → fixed |
| Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.



Committed to 1.2-stable in r15781, merged in r15782.