Streamlining some code in marker_cluster
@@ -68,8 +68,8 @@ class MarkerCluster(Layer):
if icons is None:
icons = [None] * len(locations)
for location, popup, icon in zip(locations, popups, icons):
- p = popup if popup is None or isinstance(popup, Popup) else Popup(popup) # noqa
- i = icon if icon is None or isinstance(icon, Icon) else Icon(icon) # noqa
+ p = popup if self._validate(popup, Popup) else Popup(popup)
+ i = icon if self._validate(icon, Icon) else Icon(icon)
self.add_child(Marker(location, popup=p, icon=i))
options = {} if options is None else options
@@ -77,6 +77,11 @@ class MarkerCluster(Layer):
options['iconCreateFunction'] = icon_create_function.strip()
self.options = json.dumps(options, sort_keys=True, indent=2)
+ @staticmethod
+ def _validate(obj, cls):
+ """Check whether the given object is from the given class or is None."""
+ return True if obj is None or isinstance(obj, cls) else False
+
def render(self, **kwargs):
super(MarkerCluster, self).render(**kwargs)
