-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
bpo-30296 Remove unnecessary tuples, lists, sets, and dicts #1489
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
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! |
Lib/_weakrefset.py
Outdated
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.
Let's use: set(map(ref, other)) for all of these.
Lib/distutils/msvc9compiler.py
Outdated
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.
Yes to this one. Set literals are always a win.
Lib/inspect.py
Outdated
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.
Yes, this one is fine.
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.
I would keep the original code.
Lib/ntpath.py
Outdated
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.
This code smells bad (both the original and revision). Can this be replaced with any(...).
Lib/optparse.py
Outdated
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.
This looks like a reasonable change, but optparse is essentially defunct so we should leave it alone.
Tools/stringbench/stringbench.py
Outdated
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.
I prefer not to touch a benchmark file lest it cause comparability issues.
setup.py
Outdated
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.
Skip this. I prefer not to touch anything in setup.py.
setup.py
Outdated
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.
Skip
setup.py
Outdated
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.
Skip
setup.py
Outdated
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.
Ambivalent.
terryjreedy
left a comment
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.
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.
Lib/idlelib/multicall.py
Outdated
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.
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.)
Lib/idlelib/multicall.py
Outdated
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.
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())
Lib/email/headerregistry.py
Outdated
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.
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.
Lib/inspect.py
Outdated
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would keep the original code.
Maybe unpack a tuple:
tuple([i + j for i, j in zip(caller, new_callers[func])])
Lib/symtable.py
Outdated
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.
I would keep the original code.
Lib/turtle.py
Outdated
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.
I would keep the original code.
Lib/turtle.py
Outdated
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.
.keys() can be removed. Iterate just docsdict.
Lib/urllib/request.py
Outdated
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Tools/gdb/libpython.py
Outdated
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.
I would keep the original code.
max())