display_formatter.active_types does not mirror each formatter enabled state. #10662

Open
Carreau opened this Issue Jun 12, 2017 · 0 comments

Comments

Projects
None yet
1 participant
Owner

Carreau commented Jun 12, 2017

I'm attempting to enable PNG formatter in terminal (for tests). The Display Formatter have the following:

class DisplayFormatter(Configurable):

    active_types = List(Unicode(),
        help="""List of currently active mime-types to display.
        You can use this to set a white-list for formats to display.

        Most users will not need to change this value.
        """).tag(config=True)

    @default('active_types')
    def _active_types_default(self):
        return self.format_types

    @observe('active_types')
    def _active_types_changed(self, change):
        for key, formatter in self.formatters.items():
            if key in change['new']:
                formatter.enabled = True
            else:
                formatter.enabled = False

Though:

In [9]: ip.display_formatter.active_types.append('image/png')

In [10]: ip.display_formatter.formatters['image/png'].enabled
Out[10]: False

You do need to assign to the trait:

In [11]: ip.display_formatter.active_types = ['image/png','text/plain']

In [12]: ip.display_formatter.formatters['image/png'].enabled
Out[12]: True

Which is far from being obvious, and made me scratch my head for about 30 min.

It seem to me that this way of enabling/disabling formatters should be cleaned-up in order to make it impossible to be wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment