Skip to content

Commit

Permalink
Apply attribute name validation to entire declarative interface
Browse files Browse the repository at this point in the history
In this commit, the ValidationMixin is applied to all of the objects
in the declarative plotting interface intended for external use.
  • Loading branch information
sgdecker committed Oct 25, 2021
1 parent 91ec453 commit 14912fd
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/metpy/plots/declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,10 @@ def _levenshtein(s1, s2):
return distances[-1]

whitelist = ['ax',
'data',
'handle',
'notify_change',
'panel'
]

whitelist.extend(self.trait_names())
Expand Down Expand Up @@ -560,7 +563,7 @@ class Panel(MetPyHasTraits):


@exporter.export
class PanelContainer(MetPyHasTraits):
class PanelContainer(MetPyHasTraits, ValidationMixin):
"""Collects panels and set complete figure related settings (e.g., size)."""

size = Union([Tuple(Union([Int(), Float()]), Union([Int(), Float()])),
Expand Down Expand Up @@ -1238,7 +1241,7 @@ class ColorfillTraits(MetPyHasTraits):


@exporter.export
class ImagePlot(PlotScalar, ColorfillTraits):
class ImagePlot(PlotScalar, ColorfillTraits, ValidationMixin):
"""Make raster image using `~matplotlib.pyplot.imshow` for satellite or colored image."""

@observe('colormap', 'image_range')
Expand Down Expand Up @@ -1293,7 +1296,7 @@ def _build(self):


@exporter.export
class ContourPlot(PlotScalar, ContourTraits):
class ContourPlot(PlotScalar, ContourTraits, ValidationMixin):
"""Make contour plots by defining specific traits."""

linecolor = Unicode('black')
Expand Down Expand Up @@ -1342,7 +1345,7 @@ def _build(self):


@exporter.export
class FilledContourPlot(PlotScalar, ColorfillTraits, ContourTraits):
class FilledContourPlot(PlotScalar, ColorfillTraits, ContourTraits, ValidationMixin):
"""Make color-filled contours plots by defining appropriate traits."""

@observe('contours', 'colorbar', 'colormap')
Expand Down Expand Up @@ -1514,7 +1517,7 @@ def draw(self):


@exporter.export
class BarbPlot(PlotVector):
class BarbPlot(PlotVector, ValidationMixin):
"""Make plots of wind barbs on a map with traits to refine the look of plotted elements."""

barblength = Float(default_value=7)
Expand Down Expand Up @@ -1550,7 +1553,7 @@ def _build(self):


@exporter.export
class PlotObs(MetPyHasTraits):
class PlotObs(MetPyHasTraits, ValidationMixin):
"""The highest level class related to plotting observed surface and upperair data.
This class collects all common methods no matter whether plotting a upper-level or
Expand Down

0 comments on commit 14912fd

Please sign in to comment.