Edgewall Software
Modify

Opened 8 years ago

Closed 8 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:

to_list in trac.util returns an empty list on falsy input.

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):  
    13071307def to_list(splittable, sep=','):
    13081308    """Split a string at `sep` and return a list without any empty items.
    13091309    """
     1310    if not splittable:
     1311        return []
    13101312    split = [x.strip() for x in splittable.split(sep)]
    13111313    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 Ryan J Ollos, 8 years ago

API Changes: modified (diff)
Resolution: fixed
Status: assignedclosed

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

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Ryan J Ollos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.