◐ Shell
reader mode source ↗
Skip to content

bpo-30152: Reduce the number of imports for argparse.#1269

Merged
serhiy-storchaka merged 11 commits into
python:masterfrom
serhiy-storchaka:argparse-reduce-import
Sep 25, 2017
Merged

bpo-30152: Reduce the number of imports for argparse.#1269
serhiy-storchaka merged 11 commits into
python:masterfrom
serhiy-storchaka:argparse-reduce-import

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Apr 24, 2017

Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka added the type-feature A feature request or enhancement label Apr 24, 2017
@mention-bot

Copy link
Copy Markdown

@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.

@nedbat

nedbat commented Apr 27, 2017

Copy link
Copy Markdown
Member

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).

@wm75

wm75 commented Apr 28, 2017

Copy link
Copy Markdown

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?

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

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).

@wm75

wm75 commented May 3, 2017

Copy link
Copy Markdown

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?

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

Good idea. Thanks @wm75.

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide comment

A few questions.

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

Got rid of importing errno.

@methane methane left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide comment

LGTM

@serhiy-storchaka serhiy-storchaka merged commit 8110837 into python:master Sep 25, 2017
@serhiy-storchaka serhiy-storchaka deleted the argparse-reduce-import branch September 25, 2017 21:55
eli-schwartz added a commit to eli-schwartz/cpython that referenced this pull request Jan 16, 2025
…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
eli-schwartz added a commit to eli-schwartz/cpython that referenced this pull request Jan 16, 2025
…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
eli-schwartz added a commit to eli-schwartz/cpython that referenced this pull request Jan 17, 2025
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.