bpo-30152: Reduce the number of imports for argparse.#1269
Conversation
|
@serhiy-storchaka, thanks for your PR! By analyzing the history of the files in this pull request, we identified @benjaminp, @bitdancer and @akheron to be potential reviewers. |
Sorry, something went wrong.
|
People read the stdlib expecting to find best practices. As the discussion on bpo makes clear, these changes are controversial. Could we at least have some comments explaining the unusual lines of code (imports inside functions). |
Sorry, something went wrong.
|
Regarding the import of copy, I'm not quite sure why it is used at all in the AppendAction/AppendConstAction. Couldn't it be replaced with a simple slice copy of the lists? |
Sorry, something went wrong.
|
The default value can be not a list. It can be a deque or a custom sequence with special append method (see an example in https://bugs.python.org/issue16399). |
Sorry, something went wrong.
|
I see, thanks. What may be possible though is to make the import of copy even more conditional by first trying a slice copy (which I guess would succeed in > 90% of cases), and resort to copy.copy only if that raises. Maybe needing copy.copy only in very exotic cases makes the unconventional inside-a-function import a bit more justifiable? |
Sorry, something went wrong.
vstinner
left a comment
There was a problem hiding this comment.
A few questions.
Sorry, something went wrong.
|
Got rid of importing |
Sorry, something went wrong.
methane
left a comment
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
…port The same change was made, and for the same reason, by argparse back in 2017. The textwrap module is only used when printing help text, so most invocations will never need it imported. See: python#1269 See: 8110837
…port The same change was made, and for the same reason, by argparse back in 2017. The textwrap module is only used when printing help text, so most invocations will never need it imported. See: python#1269 See: 8110837
…port The same change was made, and for the same reason, by argparse back in 2017. The textwrap module is only used when printing help text, so most invocations will never need it imported. See: python#1269 See: 8110837
https://bugs.python.org/issue30152