Edgewall Software
Modify

Opened 7 years ago

Closed 6 years ago

Last modified 3 years ago

#10541 closed defect (fixed)

ListOption seems to ignore/suppress 0

Reported by: chris.nelson.1022@… Owned by: Jun Omae
Priority: normal Milestone: 1.0.1
Component: general Version: 0.11.6
Severity: major Keywords: config
Cc:
Release Notes:

ListOption keeps values other than empty string and None in raw list as default.

API Changes:

Description (last modified by Ryan J Ollos <ryan.j.ollos@…>)

I'm trying to add a list of work days (days of the week) to TeamCalendar plugin. Near the top I do:

class TeamCalendar(Component):
    implements(INavigationContributor, IRequestHandler, IPermissionRequestor, 
               ITemplateProvider)

...
    # Default work week.
    work_days = ListOption('team-calendar',
                            'work_days',
                            [0, 1, 2, 3, 4],
                            doc="Lists days of week that are worked. " + \
                                "Defaults to none.  0 is Monday.")

and later

        self.env.log.debug('work_days: %s ' % self.work_days)

        timetable = {}
        current_date = from_date
        while current_date <= to_date:
            if current_date.weekday() in self.work_days:

The log does not show the 0, only 1..4. If I set the default to [99, 0, 1, 2, 3, 4], the log shows 99 but not 0 so it isn't the first element that's getting dropped.

Attachments (0)

Change History (8)

comment:1 Changed 6 years ago by Jun Omae

Keywords: config added
Milestone: 1.0.1

Reproduced. ListOption drops 0 (int) and 0.0 (float) from raw list as default value.

Workaround is to specify string as default value.

    work_days = ListOption('team-calendar',
                           'work_days',
                           '0, 1, 2, 3, 4',
                           doc="Lists days of week that are worked. " + \
                                "Defaults to none. 0 is Monday."

If did fix this…

  • trac/config.py

     
    455455        else:
    456456            items = list(value)
    457457        if not keep_empty:
    458             items = filter(None, items)
     458            items = filter(lambda val: val or val is not None and \
     459                                       not isinstance(val, basestring),
     460                           items)
    459461        return items
    460462
    461463    def getpath(self, key, default=''):
  • trac/tests/config.py

     
    172172                    config.getlist('b', 'option2', ['foo', 'bar', 'baz']))
    173173        self.assertEquals(['foo', 'bar', 'baz'],
    174174                    config.getlist('b', 'option2', 'foo, bar, baz'))
     175        self.assertEquals([-1, 0, 1],
     176                          config.getlist('c', 'int', [-1, 0, 1]))
     177        self.assertEquals([-1.0, 0.0, 1.0],
     178                          config.getlist('c', 'float', [-1.0, 0.0, 1.0]))
    175179
    176180    def test_read_and_getlist_sep(self):
    177181        self._write(['[a]', 'option = foo | bar | baz'])

comment:2 Changed 6 years ago by Christian Boos

If we're not using filter(None, ), we could as well use a list comprehension here?

items = [v for v in items if v or v is not None etc.]

And for the test itself, in trunk we could use isinstance(v, numbers.Number) if we indeed switch to Python 2.6 as a base requirement.

comment:3 in reply to:  2 Changed 6 years ago by Jun Omae

Replying to cboos:

If we're not using filter(None, ), we could as well use a list comprehension here?

items = [v for v in items if v or v is not None etc.]

Oh, yes. Thanks ;-)

  • trac/config.py

     
    455455        else:
    456456            items = list(value)
    457457        if not keep_empty:
    458             items = filter(None, items)
     458            items = [v for v in items
     459                       if v or isinstance(v, (int, long, float))]
    459460        return items
    460461
    461462    def getpath(self, key, default=''):

I'll apply later.

comment:4 Changed 6 years ago by Jun Omae

Release Notes: modified (diff)
Resolution: fixed
Status: newclosed

Fixed in [11478-11479].

comment:5 Changed 6 years ago by Jun Omae

Owner: set to Jun Omae

comment:6 Changed 6 years ago by Ryan J Ollos <ryan.j.ollos@…>

Description: modified (diff)
Release Notes: modified (diff)

comment:7 Changed 4 years ago by Ryan J Ollos

Reporter: changed from Chris Nelson <Chris.Nelson@…> to Chris Nelson <Chris.Nelson@…>

comment:8 Changed 3 years ago by Ryan J Ollos

Reporter: changed from Chris Nelson <Chris.Nelson@…> to chris.nelson.1022@…

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted.
to The owner will be changed from Jun Omae 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.