MCPcopy Index your code
hub / github.com/plotly/plotly.py / validate_coerce

Method validate_coerce

_plotly_utils/basevalidators.py:1787–1820  ·  view source on GitHub ↗
(self, v)

Source from the content-addressed store, hash-verified

1785 return desc
1786
1787 def validate_coerce(self, v):
1788 def coerce(value):
1789 if not isinstance(value, str):
1790 return value, False
1791 match = fullmatch(self.regex, value)
1792 if not match:
1793 return value, False
1794 else:
1795 digit_str = match.group(1)
1796 if len(digit_str) > 0 and int(digit_str) == 0:
1797 return value, False
1798 elif len(digit_str) > 0 and int(digit_str) == 1:
1799 return self.base, True
1800 else:
1801 return value, True
1802
1803 if v is None:
1804 pass
1805 elif self.array_ok and is_simple_array(v):
1806 values = []
1807 invalid_els = []
1808 for e in v:
1809 coerced_e, success = coerce(e)
1810 values.append(coerced_e)
1811 if not success:
1812 invalid_els.append(coerced_e)
1813 if len(invalid_els) > 0:
1814 self.raise_invalid_elements(invalid_els[:10])
1815 return values
1816 else:
1817 v, success = coerce(v)
1818 if not success:
1819 self.raise_invalid_val(self.base)
1820 return v
1821
1822
1823class FlaglistValidator(BaseValidator):

Callers

nothing calls this directly

Calls 3

is_simple_arrayFunction · 0.85
raise_invalid_valMethod · 0.80

Tested by

no test coverage detected