bpo-30296 Remove unnecessary tuples, lists, sets, and dicts#1489
Conversation
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. Thanks again to your contribution and we look forward to looking at it! |
There was a problem hiding this comment.
Let's use: set(map(ref, other)) for all of these.
There was a problem hiding this comment.
Yes to this one. Set literals are always a win.
There was a problem hiding this comment.
I would keep the original code.
There was a problem hiding this comment.
This code smells bad (both the original and revision). Can this be replaced with any(...).
There was a problem hiding this comment.
This looks like a reasonable change, but optparse is essentially defunct so we should leave it alone.
There was a problem hiding this comment.
I prefer not to touch a benchmark file lest it cause comparability issues.
There was a problem hiding this comment.
Skip this. I prefer not to touch anything in setup.py.
terryjreedy
left a comment
There was a problem hiding this comment.
I keep idlelib 3.6 and 3.7 in sync as much as possible.
Please remove all Lib/idlelib/multicall.py changes from this PR and optionally (and preferably) make the 2 approved changes in a separate PR that can be backported easily.
There was a problem hiding this comment.
I prefer the change as easier to read and likely faster. Ditto for the other dict(list) to dict comp change in this file. (Agreeing with Raymond.)
There was a problem hiding this comment.
Agree with Raymond, leave as is.
|
Thanks for the reviews! I believe I have addressed all feedback comments. If I missed or misunderstood any of the previous comments, please let me know. |
* Replaced list(<generator expression>) with list comprehension * Replaced dict(<generator expression>) with dict comprehension * Replaced set(<list literal>) with set literal * Replaced builtin func(<list comprehension>) with func(<generator expression>) when supported (e.g. any(), all(), tuple(), min(), & max())
There was a problem hiding this comment.
The original variant, with list comprehension, is faster than the variant with a generator. The difference is up to 2 times for simple tests.
I would keep the original code.
There was a problem hiding this comment.
I would keep the original code.
| props = config.pop('.', None) | ||
| # Check for valid identifiers | ||
| kwargs = dict([(k, config[k]) for k in config if valid_ident(k)]) | ||
| kwargs = dict((k, config[k]) for k in config if valid_ident(k)) |
There was a problem hiding this comment.
I would use a dict comprehension.
And the same for other change in this file.
| # format used by cProfile | ||
| new_callers[func] = tuple([i[0] + i[1] for i in | ||
| zip(caller, new_callers[func])]) | ||
| new_callers[func] = tuple(i[0] + i[1] for i in zip(caller, new_callers[func])) |
There was a problem hiding this comment.
I would keep the original code.
Maybe unpack a tuple:
tuple([i + j for i, j in zip(caller, new_callers[func])])
There was a problem hiding this comment.
I would keep the original code.
There was a problem hiding this comment.
I would keep the original code.
There was a problem hiding this comment.
.keys() can be removed. Iterate just docsdict.
There was a problem hiding this comment.
I would keep the original code.
| headers = dict(req.unredirected_hdrs) | ||
| headers.update(dict((k, v) for k, v in req.headers.items() | ||
| if k not in headers)) | ||
| headers.update((k, v) for k, v in req.headers.items() if k not in headers) |
There was a problem hiding this comment.
This changes the semantic. Updated headers is used in the generator expression. I don't know whether this is good.
I would use a dict comprehesion.
There was a problem hiding this comment.
I would keep the original code.
max())