Skip to content

Audit __getstate__ and __setstate__ methods #583

@corranwebster

Description

@corranwebster

There are a number of Chaco classes which override __getstate__ and possibly __setstate__. Most of these seem to be removing traits from the state dict, which is now correctly handled by marking those traits as transient.

For example:

chaco/chaco/lineplot.py

Lines 415 to 421 in e342361

def __getstate__(self):
state = super(LinePlot,self).__getstate__()
for key in ['traits_view']:
if key in state:
del state[key]
return state

This is removing the traits_view trait from the state - under normal Traits, this will never be in the state because of special handling of Views, so this whole method can be removed.

Another example:

chaco/chaco/grid.py

Lines 413 to 419 in e342361

def __getstate__(self):
state = super(PlotGrid,self).__getstate__()
for key in ['_cache_valid', '_tick_list', '_tick_positions', '_tick_extents']:
if key in state:
del state[key]
return state

Here the traits _cache_valid, _tick_list, _tick_positions, _tick_extents are being removed from the state. These traits should be marked with transient=True metadata and then the __getstate__ method can be removed.

If it turns out that there are necessary things being done in a __getstate__, we should make sure that there is a super call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions