-
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?
Conversation
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.
Sourcery timed out performing refactorings.
Due to GitHub API limits, only the first 60 comments can be shown.
|
||
setup(name="plotly") |
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.
Lines 12-13
refactored with the following changes:
- Remove unreachable code (
remove-unreachable-code
)
# print(submodules_str) | ||
|
||
autosubmodule = "" | ||
|
||
for submodule in submodules: | ||
autosubmodule += ( | ||
".. automodule:: plotly.graph_objects.%s\n :members:\n\n" % submodule | ||
) | ||
autosubmodule = "".join( | ||
(".. automodule:: plotly.graph_objects.%s\n :members:\n\n" % submodule) | ||
for submodule in submodules | ||
) |
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.
"{} is not a valid config or credentials key".format(key) | ||
f"{key} is not a valid config or credentials key" |
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 sign_in
refactored with the following changes:
- Replace call to format with f-string [×4] (
use-fstring-for-formatting
)
"{} is not a valid config or plot option key".format(key) | ||
f"{key} is not a valid config or plot option key" | ||
) | ||
if not isinstance(kwargs[key], PLOT_OPTIONS[key]): | ||
raise _plotly_utils.exceptions.PlotlyError( | ||
"{} must be of type '{}'".format(key, PLOT_OPTIONS[key]) | ||
f"{key} must be of type '{PLOT_OPTIONS[key]}'" | ||
) | ||
|
||
# raise exception if sharing is invalid | ||
if key == "sharing" and not (kwargs[key] in SHARING_OPTIONS): | ||
if key == "sharing" and kwargs[key] not in SHARING_OPTIONS: |
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 update_session_plot_options
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
) - Simplify logical expression using De Morgan identities (
de-morgan
)
# to check for share_key we check urlsplit.query | ||
query_dict = six.moves.urllib.parse.parse_qs(urlsplit.query) | ||
if query_dict: | ||
if query_dict := six.moves.urllib.parse.parse_qs(urlsplit.query): |
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 _get_embed_url
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
This removes the following comments ( why? ):
# to check for share_key we check urlsplit.query
container = { | ||
return { |
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 _container
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
# remove path 'second' as it's always an empty box | ||
all_paths = [] | ||
for node in all_nodes: | ||
all_paths.append(node[1]) | ||
all_paths = [node[1] for node in all_nodes] |
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 Dashboard._make_all_nodes_and_paths
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
)
This removes the following comments ( why? ):
# remove path 'second' as it's always an empty box
new_top_left_x = top_left_x | ||
new_top_left_y = top_left_y | ||
# determine the specs for resulting two box split | ||
if is_horizontal: | ||
new_top_left_x = top_left_x | ||
new_top_left_y = top_left_y |
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 Dashboard.get_preview
refactored with the following changes:
- Hoist repeated code outside conditional statement [×2] (
hoist-statement-from-if
)
if len(jdata) > max_chars: | ||
data_string = jdata[:max_chars] + "...]" | ||
else: | ||
data_string = jdata | ||
data_string = f"{jdata[:max_chars]}...]" if len(jdata) > max_chars else jdata |
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 Column.__str__
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
duplicate_name = utils.get_first_duplicate(columns_or_json.columns) | ||
if duplicate_name: | ||
if duplicate_name := utils.get_first_duplicate( | ||
columns_or_json.columns | ||
): | ||
err = exceptions.NON_UNIQUE_COLUMN_MESSAGE.format(duplicate_name) | ||
raise exceptions.InputError(err) | ||
|
||
# create columns from dataframe | ||
all_columns = [] | ||
for name in columns_or_json.columns: | ||
all_columns.append(Column(columns_or_json[name].tolist(), name)) | ||
all_columns = [ | ||
Column(columns_or_json[name].tolist(), name) | ||
for name in columns_or_json.columns | ||
] |
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 Grid.__init__
refactored with the following changes:
- Use named expression to simplify assignment and conditional [×2] (
use-named-expression
) - Convert for loop into list comprehension [×2] (
list-comprehension
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
This removes the following comments ( why? ):
# collect and sort all orders in case orders do not start
# create columns from dataframe
# at zero or there are jump discontinuities between them
column_id = None | ||
for column in self._columns: | ||
if column.name == column_name: | ||
column_id = column.id | ||
break | ||
|
||
column_id = next( | ||
(column.id for column in self._columns if column.name == column_name), | ||
None, | ||
) | ||
if column_id is None: | ||
col_names = [] | ||
for column in self._columns: | ||
col_names.append(column.name) | ||
col_names = [column.name for column in self._columns] |
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 Grid.get_column_reference
refactored with the following changes:
- Use the built-in function
next
instead of a for-loop (use-next
) - Convert for loop into list comprehension (
list-comprehension
)
user_plot_options.update(default_plot_options) | ||
user_plot_options |= default_plot_options |
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 _plot_option_logic
refactored with the following changes:
- Merge dictionary updates via the union operator (
dict-assign-update-to-union
)
embed_options = dict() | ||
embed_options["width"] = layout.get("width", "100%") | ||
embed_options = {"width": layout.get("width", "100%")} |
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 iplot
refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign
) - Replace
dict()
with{}
(dict-literal
)
filename = filename[0:-1] | ||
filename = filename[:-1] | ||
|
||
# split off any parent directory | ||
paths = filename.split("/") | ||
parent_path = "/".join(paths[0:-1]) | ||
parent_path = "/".join(paths[:-1]) |
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 plot
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] [×2] (
remove-redundant-slice-index
) - Use f-string instead of string concatenation [×4] (
use-fstring-for-concatenation
)
This removes the following comments ( why? ):
# Handle auto_open
data_obj["z"] = [[0 for rrr in range(rows)] for ccc in range(cols)] | ||
data_obj["z"] = [[0 for _ in range(rows)] for _ in range(cols)] |
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 _swap_xy_data
refactored with the following changes:
- Replace unused for index with underscore [×2] (
for-index-underscore
) - Replace call to format with f-string (
use-fstring-for-formatting
)
fid = "{}:{}".format(username, idlocal) | ||
fid = f"{username}:{idlocal}" |
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 add_share_key_to_url
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
if raw: | ||
return parsed_content | ||
return Grid(parsed_content, fid) | ||
return parsed_content if raw else Grid(parsed_content, fid) |
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 get_grid
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
api_module = getattr(v2, filetype + "s") | ||
api_module = getattr(v2, f"{filetype}s") |
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 _create_or_update
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
if sharing == "public": | ||
world_readable = True | ||
elif sharing == "private": | ||
if sharing in ["private", "secret"]: | ||
world_readable = False | ||
elif sharing == "secret": | ||
world_readable = False | ||
|
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 dashboard_ops.upload
refactored with the following changes:
- Simplify conditional into switch-like form (
switch
)
dashboards = [] | ||
res = v2.dashboards.list().json() | ||
|
||
for dashboard in res["results"]: | ||
if not dashboard["deleted"]: | ||
dashboards.append(dashboard) | ||
dashboards = [ | ||
dashboard for dashboard in res["results"] if not dashboard["deleted"] | ||
] |
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 dashboard_ops._get_all_dashboards
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Convert for loop into list comprehension (
list-comprehension
)
if only_content: | ||
dashboard_json = json.loads(dashboard["content"]) | ||
return dashboard_json | ||
else: | ||
return dashboard | ||
return json.loads(dashboard["content"]) if only_content else dashboard |
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 dashboard_ops._get_dashboard_json
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
propsrc = "{}src".format(prop) | ||
propsrc = f"{prop}src" |
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 _extract_grid_graph_obj
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
raise ValueError("Invalid figure type {}".format(type(fig))) | ||
raise ValueError(f"Invalid figure type {type(fig)}") |
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 _extract_grid_from_fig_like
refactored with the following changes:
- Replace call to format with f-string [×3] (
use-fstring-for-formatting
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
prop_parent[prop_path[-1] + "src"] = col.id | ||
prop_parent[f"{prop_path[-1]}src"] = col.id |
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 _set_grid_column_references
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
embed_options = dict() | ||
embed_options["width"] = layout.get("width", "100%") | ||
embed_options = {"width": layout.get("width", "100%")} |
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 icreate_animations
refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign
) - Replace
dict()
with{}
(dict-literal
)
if grouptype == "rightgroup_v": | ||
left_shift = 100 - width_range | ||
else: | ||
left_shift = 0 | ||
|
||
left_shift = 100 - width_range if grouptype == "rightgroup_v" else 0 |
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 _box_specs_gen
refactored with the following changes:
- Replace if statement with if expression [×3] (
assign-if-exp
) - Hoist for/while loops out of nested conditionals (
hoist-loop-from-if
) - Hoist repeated code outside conditional statement [×5] (
hoist-statement-from-if
) - Hoist statements out of for/while loops (
hoist-statement-from-loop
)
if num_of_boxes == 0 and slide_num == 0: | ||
text_textAlign = "center" | ||
else: | ||
text_textAlign = "left" | ||
text_textAlign = "center" if num_of_boxes == 0 and slide_num == 0 else "left" |
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 _return_layout_specs
refactored with the following changes:
- Replace if statement with if expression [×4] (
assign-if-exp
) - Split conditional into multiple branches (
split-or-ifs
) - Remove redundant conditional (
remove-redundant-if
) - Hoist repeated code outside conditional statement [×4] (
hoist-statement-from-if
)
This removes the following comments ( why? ):
# left
# middle across
return line.startswith(url_name + "(") and line.endswith(")") | ||
return line.startswith(f"{url_name}(") and line.endswith(")") |
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 _url_parens_contained
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
expected_message = ( | ||
"Yikes, plotly grids currently " | ||
"can't have duplicate column names. Rename " | ||
'the column "{}" and try again.'.format("col_1") | ||
) | ||
expected_message = """Yikes, plotly grids currently can't have duplicate column names. Rename the column "col_1" and try again.""" |
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 TestDataframeToGrid.test_duplicate_columns
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
) - Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
self.assertEqual(url, "{}/v2/files/hodor:88".format(self.plotly_api_domain)) | ||
self.assertEqual(url, f"{self.plotly_api_domain}/v2/files/hodor:88") |
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 FilesTest.test_retrieve
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
Branch
master
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run:Help us improve this pull request!