Edgewall Software
Modify

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#8763 closed defect (worksforme)

ListOption doesn't always work as expected

Reported by: Jeff Hammel <jhammel@…> Owned by: rblank
Priority: normal Milestone:
Component: general Version: 0.11.5
Severity: normal Keywords:
Cc:
Release Notes:
API Changes:

Description

ListOption does not always unpack values. Given the example code:

class StyleMarkers(Component):
    """apply a static style to the markers"""

    implements(IMapMarkerStyle)

    styles = ListOption('geo', 'static_marker_style', '',
                        "static styles to apply to markers")

    def style(self, ticket, req, **style):
        retval = {}
        import pdb; pdb.set_trace()
        for s in self.styles:
            key, value = s.split(':', 1)
            key = key.strip()
            value = value.strip()
            if key not in style:
                retval[key] = value
        return retval

in trac.ini

static_marker_style = fillOpacity: 0.3, graphicOpacity: 0.3, strokeOpacity: 0.3

However, upon hitting the pdb, the values are not unpacked:

(Pdb) self.styles
[u'fillOpacity: 0.3, graphicOpacity: 0.3, strokeOpacity: 0.3']

However, self.env.config.getlist does work as expected:

(Pdb) self.env.config.getlist('geo', 'static_marker_style')
[u'fillOpacity: 0.3', u'graphicOpacity: 0.3', u'strokeOpacity: 0.3']

I will use getlist for now, but would love to see the API fixed properly so I didn't have to do work arounds. I've noticed this bug off and on. Not sure what the reason for it is or why it seems intermittent

Attachments (0)

Change History (3)

comment:1 Changed 5 years ago by rblank

  • Milestone set to 0.11.6
  • Owner set to rblank

I'm working on the config module, so I'll look into this.

comment:2 Changed 5 years ago by rblank

  • Milestone 0.11.6 deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Be careful how you pass the docstring to the ListOption. In your example, you're actually passing it as the sep= argument, which is the list separator. You should use the following instead:

styles = ListOption('geo', 'static_marker_style', '',
                    doc="static styles to apply to markers")

Note the doc=.

comment:3 Changed 5 years ago by rblank

Oh, and please use the MailingList or the IrcChannel for support questions ;-)

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed The owner will remain rblank.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from rblank to the specified user.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.