Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-36405: IDLE - Restore __main__ and add tests#12518

Merged
terryjreedy merged 2 commits into
python:masterpython/cpython:masterfrom
terryjreedy:main_restoreterryjreedy/cpython:main_restoreCopy head branch name to clipboard
Mar 24, 2019
Merged

bpo-36405: IDLE - Restore __main__ and add tests#12518
terryjreedy merged 2 commits into
python:masterpython/cpython:masterfrom
terryjreedy:main_restoreterryjreedy/cpython:main_restoreCopy head branch name to clipboard

Conversation

@terryjreedy

@terryjreedy terryjreedy commented Mar 23, 2019

Copy link
Copy Markdown
Member

Fix error in commit 2b75155 noticed by Serhiy Storchaka.

https://bugs.python.org/issue36405

Fix error in commit 2b75155 noticed by Serhiy Storchaka.
Comment thread Lib/idlelib/autocomplete.py Outdated
small, large = self.autocomplete.fetch_completions(
'', ac.COMPLETE_ATTRIBUTES)
self.assertLess(len(small), len(large))
self.assertTrue('AutoComplete' not in small or # See issue 36405.

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.

I dislike complex expressions in assertTrue() because it gives little information when the test is failed and it is easy to make an error that makes the test be always passed.

If I understand the problem correctly, this could be written as:

if __main__ is idlelib.autocomplete:
    self.assertIn('testing_in_autocomplete', small)
else:
    self.assertNotIn('AutoComplete', small)

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.

I agree about disliking what is a bit of a kludge. However, even when autocomplete.py is run, main and idlelib.autocomplete (ac) are different and unequal module instances, with different names ('main' and 'idlelib.autocomplete'), different types for builtins (module and dict), and unique attributes (annotations and cached). What are equal if and only if both modules derived from the same file are the __file__s. Test code added to test_autocomplete.

        print(__main__, ac, __main__ is ac)
        print(type(__main__.__builtins__), type(ac.__builtins__))
        print(dir(__main__))
        print(dir(ac))
        print(__main__.__file__, ac.__file__)

The goal is to detect whether the merged dict is main.dict (right) or autocomplete globals() (wrong). When the test is run with autocomplete as main, they are the same, so there is nothing to test. We must either skip 'AutoComplete not in small' or add something to make the resulting expression true. I did the latter, but former will be nicer. The following works.

    if __main__.__file__ != ac.__file__:
        self.assertNotIn('AutoComplete', small)

Thank you for the hint of where to look.

Comment thread Lib/idlelib/calltip.py Outdated
@terryjreedy terryjreedy merged commit 0fe4513 into python:master Mar 24, 2019
@bedevere-bot

Copy link
Copy Markdown

@terryjreedy: Please replace # with GH- in the commit message next time. Thanks!

@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @terryjreedy for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@bedevere-bot

Copy link
Copy Markdown

GH-12526 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 24, 2019
Fix error in commit 2b75155 noticed by Serhiy Storchaka.
(cherry picked from commit 0fe4513)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
@terryjreedy terryjreedy deleted the main_restore branch March 24, 2019 21:12
miss-islington added a commit that referenced this pull request Mar 24, 2019
Fix error in commit 2b75155 noticed by Serhiy Storchaka.
(cherry picked from commit 0fe4513)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.