-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,10 +18,7 @@ | |
| # back-port of fullmatch from Py3.4+ | ||
| def fullmatch(regex, string, flags=0): | ||
| """Emulate python-3.4 re.fullmatch().""" | ||
| if "pattern" in dir(regex): | ||
| regex_string = regex.pattern | ||
| else: | ||
| regex_string = regex | ||
| regex_string = regex.pattern if "pattern" in dir(regex) else regex | ||
| return re.match("(?:" + regex_string + r")\Z", string, flags=flags) | ||
|
|
||
|
|
||
|
|
@@ -181,10 +178,7 @@ def is_homogeneous_array(v): | |
| if np: | ||
| v_numpy = np.array(v) | ||
| # v is essentially a scalar and so shouldn't count as an array | ||
| if v_numpy.shape == (): | ||
| return False | ||
| else: | ||
| return True | ||
| return v_numpy.shape != () | ||
|
Comment on lines
-184
to
+181
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return False | ||
|
|
||
|
|
||
|
|
@@ -788,9 +782,8 @@ def validate_coerce(self, v): | |
| self.raise_invalid_val(v) | ||
|
|
||
| # Check min/max | ||
| if self.has_min_max: | ||
| if not (self.min_val <= v <= self.max_val): | ||
| self.raise_invalid_val(v) | ||
| if self.has_min_max and not (self.min_val <= v <= self.max_val): | ||
| self.raise_invalid_val(v) | ||
|
Comment on lines
-791
to
+786
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return v | ||
|
|
||
|
|
||
|
|
@@ -918,9 +911,8 @@ def validate_coerce(self, v): | |
| self.raise_invalid_val(v) | ||
|
|
||
| # Check min/max | ||
| if self.has_min_max: | ||
| if not (self.min_val <= v <= self.max_val): | ||
| self.raise_invalid_val(v) | ||
| if self.has_min_max and not (self.min_val <= v <= self.max_val): | ||
| self.raise_invalid_val(v) | ||
|
Comment on lines
-921
to
+915
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| return v | ||
|
|
||
|
|
@@ -1073,18 +1065,18 @@ def validate_coerce(self, v): | |
| v = to_scalar_or_list(v) | ||
|
|
||
| else: | ||
| if self.strict: | ||
| if not isinstance(v, string_types): | ||
| self.raise_invalid_val(v) | ||
| else: | ||
| if isinstance(v, string_types): | ||
| pass | ||
| elif isinstance(v, (int, float)): | ||
| # Convert value to a string | ||
| v = str(v) | ||
| else: | ||
| self.raise_invalid_val(v) | ||
|
|
||
| if ( | ||
| self.strict | ||
| and not isinstance(v, string_types) | ||
| or not isinstance(v, string_types) | ||
| and not isinstance(v, (int, float)) | ||
| ): | ||
| self.raise_invalid_val(v) | ||
| elif self.strict: | ||
| pass | ||
| elif not isinstance(v, string_types): | ||
| # Convert value to a string | ||
| v = str(v) | ||
|
Comment on lines
-1076
to
+1079
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if self.no_blank and len(v) == 0: | ||
| self.raise_invalid_val(v) | ||
|
|
||
|
|
@@ -1555,7 +1547,7 @@ def description(self): | |
| ) | ||
| ) | ||
|
|
||
| desc = """\ | ||
| return """\ | ||
|
Comment on lines
-1558
to
+1550
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| The '{plotly_name}' property is a colorscale and may be | ||
| specified as: | ||
| - A list of colors that will be spaced evenly to create the colorscale. | ||
|
|
@@ -1572,8 +1564,6 @@ def description(self): | |
| plotly_name=self.plotly_name, colorscales_str=colorscales_str | ||
| ) | ||
|
|
||
| return desc | ||
|
|
||
| def validate_coerce(self, v): | ||
| v_valid = False | ||
|
|
||
|
|
@@ -1601,7 +1591,7 @@ def validate_coerce(self, v): | |
| e for e in v if ColorValidator.perform_validate_coerce(e) is None | ||
| ] | ||
|
|
||
| if len(invalid_els) == 0: | ||
| if not invalid_els: | ||
|
Comment on lines
-1604
to
+1594
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| v_valid = True | ||
|
|
||
| # Convert to list of lists colorscale | ||
|
|
@@ -1621,7 +1611,7 @@ def validate_coerce(self, v): | |
| ) | ||
| ] | ||
|
|
||
| if len(invalid_els) == 0: | ||
| if not invalid_els: | ||
| v_valid = True | ||
|
|
||
| # Convert to list of lists | ||
|
|
@@ -1641,7 +1631,7 @@ def present(self, v): | |
| elif isinstance(v, string_types): | ||
| return v | ||
| else: | ||
| return tuple([tuple(e) for e in v]) | ||
| return tuple(tuple(e) for e in v) | ||
|
Comment on lines
-1644
to
+1634
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| class AngleValidator(BaseValidator): | ||
|
|
@@ -1661,7 +1651,7 @@ def __init__(self, plotly_name, parent_name, **kwargs): | |
| ) | ||
|
|
||
| def description(self): | ||
| desc = """\ | ||
| return """\ | ||
|
Comment on lines
-1664
to
+1654
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| The '{plotly_name}' property is a angle (in degrees) that may be | ||
| specified as a number between -180 and 180. Numeric values outside this | ||
| range are converted to the equivalent value | ||
|
|
@@ -1670,8 +1660,6 @@ def description(self): | |
| plotly_name=self.plotly_name | ||
| ) | ||
|
|
||
| return desc | ||
|
|
||
| def validate_coerce(self, v): | ||
| if v is None: | ||
| # Pass None through | ||
|
|
@@ -1720,15 +1708,14 @@ def __init__(self, plotly_name, parent_name, dflt=None, regex=None, **kwargs): | |
|
|
||
| def description(self): | ||
|
|
||
| desc = """\ | ||
| return """\ | ||
|
Comment on lines
-1723
to
+1711
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| The '{plotly_name}' property is an identifier of a particular | ||
| subplot, of type '{base}', that may be specified as the string '{base}' | ||
| optionally followed by an integer >= 1 | ||
| (e.g. '{base}', '{base}1', '{base}2', '{base}3', etc.) | ||
| """.format( | ||
| plotly_name=self.plotly_name, base=self.base | ||
| ) | ||
| return desc | ||
|
|
||
| def validate_coerce(self, v): | ||
| if v is None: | ||
|
|
@@ -1833,10 +1820,10 @@ def vc_scalar(self, v): | |
| split_vals = [e.strip() for e in re.split("[,+]", v)] | ||
|
|
||
| # Are all flags valid names? | ||
| all_flags_valid = all([f in self.all_flags for f in split_vals]) | ||
| all_flags_valid = all(f in self.all_flags for f in split_vals) | ||
|
|
||
| # Are any 'extras' flags present? | ||
| has_extras = any([f in self.extras for f in split_vals]) | ||
| has_extras = any(f in self.extras for f in split_vals) | ||
|
Comment on lines
-1836
to
+1826
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| # For flaglist to be valid all flags must be valid, and if we have | ||
| # any extras present, there must be only one flag (the single extras | ||
|
|
@@ -1899,12 +1886,11 @@ def __init__(self, plotly_name, parent_name, values=None, array_ok=False, **kwar | |
|
|
||
| def description(self): | ||
|
|
||
| desc = """\ | ||
| return """\ | ||
| The '{plotly_name}' property accepts values of any type | ||
| """.format( | ||
| plotly_name=self.plotly_name | ||
| ) | ||
| return desc | ||
|
Comment on lines
-1902
to
-1907
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def validate_coerce(self, v): | ||
| if v is None: | ||
|
|
@@ -1946,7 +1932,7 @@ def __init__( | |
| ) | ||
|
|
||
| self.items = items | ||
| self.dimensions = dimensions if dimensions else 1 | ||
| self.dimensions = dimensions or 1 | ||
|
Comment on lines
-1949
to
+1935
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.free_length = free_length | ||
|
|
||
| # Instantiate validators for each info array element | ||
|
|
@@ -2329,7 +2315,7 @@ def __init__(self, plotly_name, parent_name, **kwargs): | |
|
|
||
| def description(self): | ||
|
|
||
| desc = """\ | ||
| return """\ | ||
|
Comment on lines
-2332
to
+2318
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| The '{plotly_name}' property is an image URI that may be specified as: | ||
| - A remote image URI string | ||
| (e.g. 'http://www.somewhere.com/image.png') | ||
|
|
@@ -2341,7 +2327,6 @@ def description(self): | |
| """.format( | ||
| plotly_name=self.plotly_name | ||
| ) | ||
| return desc | ||
|
|
||
| def validate_coerce(self, v): | ||
| if v is None: | ||
|
|
@@ -2423,7 +2408,7 @@ def data_class(self): | |
|
|
||
| def description(self): | ||
|
|
||
| desc = ( | ||
| return ( | ||
|
Comment on lines
-2426
to
+2411
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| """\ | ||
| The '{plotly_name}' property is an instance of {class_str} | ||
| that may be specified as: | ||
|
|
@@ -2440,8 +2425,6 @@ def description(self): | |
| constructor_params_str=self.data_docs, | ||
| ) | ||
|
|
||
| return desc | ||
|
|
||
| def validate_coerce(self, v, skip_invalid=False, _validate=True): | ||
| if v is None: | ||
| v = self.data_class() | ||
|
|
@@ -2500,7 +2483,7 @@ def __init__(self, plotly_name, parent_name, data_class_str, data_docs, **kwargs | |
|
|
||
| def description(self): | ||
|
|
||
| desc = ( | ||
| return ( | ||
|
Comment on lines
-2503
to
+2486
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| """\ | ||
| The '{plotly_name}' property is a tuple of instances of | ||
| {class_str} that may be specified as: | ||
|
|
@@ -2517,8 +2500,6 @@ def description(self): | |
| constructor_params_str=self.data_docs, | ||
| ) | ||
|
|
||
| return desc | ||
|
|
||
| @property | ||
| def data_class(self): | ||
| if self._data_class is None: | ||
|
|
@@ -2529,10 +2510,12 @@ def data_class(self): | |
|
|
||
| def validate_coerce(self, v, skip_invalid=False): | ||
|
|
||
| if v is None: | ||
| if not isinstance(v, (list, tuple)) and skip_invalid or v is None: | ||
| v = [] | ||
| elif not isinstance(v, (list, tuple)): | ||
| self.raise_invalid_val(v) | ||
|
|
||
| elif isinstance(v, (list, tuple)): | ||
| else: | ||
|
Comment on lines
-2532
to
+2518
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| res = [] | ||
| invalid_els = [] | ||
| for v_el in v: | ||
|
|
@@ -2551,12 +2534,6 @@ def validate_coerce(self, v, skip_invalid=False): | |
| self.raise_invalid_elements(invalid_els) | ||
|
|
||
| v = to_scalar_or_list(res) | ||
| else: | ||
| if skip_invalid: | ||
| v = [] | ||
| else: | ||
| self.raise_invalid_val(v) | ||
|
|
||
| return v | ||
|
|
||
| def present(self, v): | ||
|
|
@@ -2589,7 +2566,7 @@ def description(self): | |
| ) | ||
| ) | ||
|
|
||
| desc = ( | ||
| return ( | ||
|
Comment on lines
-2592
to
+2569
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| """\ | ||
| The '{plotly_name}' property is a tuple of trace instances | ||
| that may be specified as: | ||
|
|
@@ -2607,8 +2584,6 @@ def description(self): | |
| (e.g. [{{'type': 'scatter', ...}}, {{'type': 'bar, ...}}])""" | ||
| ).format(plotly_name=self.plotly_name, trace_types=trace_types_wrapped) | ||
|
|
||
| return desc | ||
|
|
||
| def get_trace_class(self, trace_name): | ||
| # Import trace classes | ||
| if trace_name not in self._class_map: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
fullmatchrefactored with the following changes:assign-if-exp)