Skip to content

bpo-30166: Import command-line parsing modules only when needed.#1293

Merged
serhiy-storchaka merged 4 commits intopython:masterfrom
serhiy-storchaka:import-argparse
May 4, 2017
Merged

bpo-30166: Import command-line parsing modules only when needed.#1293
serhiy-storchaka merged 4 commits intopython:masterfrom
serhiy-storchaka:import-argparse

Conversation

@serhiy-storchaka
Copy link
Copy Markdown
Member

No description provided.

@serhiy-storchaka serhiy-storchaka added the type-feature A feature request or enhancement label Apr 26, 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 @kbkaiser, @terryjreedy and @tim-one to be potential reviewers.

Copy link
Copy Markdown
Member

@berkerpeksag berkerpeksag left a comment

Choose a reason for hiding this comment

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

I'm not familiar with IDLE, but rest of the PR looks good to me. Just left a comment about code styling.

Thanks!

Comment thread Lib/code.py


if __name__ == "__main__":
import argparse
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.

Style nit: You may want to add a new line after import argparse like the other cases.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is a thing that compelled me to hesitate. Some usages of argparse have an empty line after imports, some doesn't have (and the majority doesn't have). I added a new line if the following code is large or separated on sections by empty lines, and didn't add it if the following code is short and dense, as in this case.

@serhiy-storchaka
Copy link
Copy Markdown
Member Author

I left reviewing IDLE on @terryjreedy.

Copy link
Copy Markdown
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

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

Moving imports not needed in the main body is consistent with what I did in Fall 2015. It is also how I introduced a bug. So I checked that os can be moved in profile.py and verified the changes in idlelib/pyshell.py. (They will be helpful if I ever move main() to a different module.) The one requested change is obviously not crucial.

Comment thread Lib/idlelib/pyshell.py Outdated
import warnings

from idlelib import testing # bool value
import idlelib
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.

Move this also to main. 'idlelib' by itself is never used in main body of module.

Comment thread Lib/profile.py


import sys
import os
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.

def trace_dispatch (line 184 in 3.6.1) is preceded by an apparently out-of-date comment
# Heavily optimized dispatch routine for os.times() timer
That os.times is no longer used is why the os import can be moved.
self.timer is now time.process time

@serhiy-storchaka serhiy-storchaka merged commit 7e4db2f into python:master May 4, 2017
@serhiy-storchaka serhiy-storchaka deleted the import-argparse branch May 4, 2017 05:17
@terryjreedy
Copy link
Copy Markdown
Member

terryjreedy commented May 4, 2017

I have backported the idlelib.pyshell part to 3.6

Copy link
Copy Markdown

@ibanezz1999 ibanezz1999 left a comment

Choose a reason for hiding this comment

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

Bahasa indonesia

@terryjreedy
Copy link
Copy Markdown
Member

@ibanezz1999 Please explain your comment. This was merged months ago and any additional changes will be a new patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants