Skip to content

Replace dict(<generator expression>) with dictionary comprehension #935

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

Merged
merged 1 commit into from
Apr 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions debug_toolbar/panels/sql/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SQLPanel(Panel):
"""
def __init__(self, *args, **kwargs):
super(SQLPanel, self).__init__(*args, **kwargs)
self._offset = dict((k, len(connections[k].queries)) for k in connections)
self._offset = {k: len(connections[k].queries) for k in connections}
self._sql_time = 0
self._num_queries = 0
self._queries = []
Expand Down Expand Up @@ -212,14 +212,14 @@ def generate_stats(self, request, response):
# Queries are duplicates only if there's as least 2 of them.
# Also, to hide queries, we need to give all the duplicate groups an id
query_colors = contrasting_color_generator()
query_duplicates = dict(
(alias, dict(
(query, (duplicate_count, next(query_colors)))
query_duplicates = {
alias: {
query: (duplicate_count, next(query_colors))
for query, duplicate_count in queries.items()
if duplicate_count >= 2
))
}
for alias, queries in query_duplicates.items()
)
}

for alias, query in self._queries:
try:
Expand Down
3 changes: 1 addition & 2 deletions debug_toolbar/panels/sql/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ def _quote_params(self, params):
if not params:
return params
if isinstance(params, dict):
return dict((key, self._quote_expr(value))
for key, value in params.items())
return {key: self._quote_expr(value) for key, value in params.items()}
return list(map(self._quote_expr, params))

def _decode(self, param):
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def render_stacktrace(trace):
stacktrace = []
for frame in trace:
params = map(escape, frame[0].rsplit(os.path.sep, 1) + list(frame[1:]))
params_dict = dict((six.text_type(idx), v) for idx, v in enumerate(params))
params_dict = {six.text_type(idx): v for idx, v in enumerate(params)}
try:
stacktrace.append('<span class="djdt-path">%(0)s/</span>'
'<span class="djdt-file">%(1)s</span>'
Expand Down