Skip to content
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

bpo-31014: webbrowser._synthesize calls webbrowser.register with outdated signature #2689

Closed
wants to merge 4 commits into from
Closed

Conversation

ghost
Copy link

@ghost ghost commented Jul 13, 2017

Tonight while running the test suite I noticed the following two errors with the tests for the webbrowser module:

======================================================================
ERROR: test_get (test.test_webbrowser.ImportTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jms/projects/forks/cpython/Lib/test/test_webbrowser.py", line 290, in test_get
    webbrowser.get('fakebrowser')
  File "/home/jms/projects/forks/cpython/Lib/webbrowser.py", line 42, in get
    register_standard_browsers()
  File "/home/jms/projects/forks/cpython/Lib/webbrowser.py", line 567, in register_standard_browsers
    cmd = _synthesize(cmdline, -1)
  File "/home/jms/projects/forks/cpython/Lib/webbrowser.py", line 116, in _synthesize
    register(browser, None, controller, update_tryorder)
TypeError: register() takes from 2 to 3 positional arguments but 4 were given

======================================================================
ERROR: test_register (test.test_webbrowser.ImportTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jms/projects/forks/cpython/Lib/test/test_webbrowser.py", line 277, in test_register
    webbrowser.register('Example1', ExampleBrowser)
  File "/home/jms/projects/forks/cpython/Lib/webbrowser.py", line 26, in register
    register_standard_browsers()
  File "/home/jms/projects/forks/cpython/Lib/webbrowser.py", line 567, in register_standard_browsers
    cmd = _synthesize(cmdline, -1)
  File "/home/jms/projects/forks/cpython/Lib/webbrowser.py", line 116, in _synthesize
    register(browser, None, controller, update_tryorder)
TypeError: register() takes from 2 to 3 positional arguments but 4 were given

----------------------------------------------------------------------

After a little bit of digging I discovered that webbrowser_synthesize is using an old call signature for webbrowser.register. This PR should fix that. I believe this is the only place the change in function signature was either affected or not updated.

https://bugs.python.org/issue31014

@the-knights-who-say-ni
Copy link

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 we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons 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!

@mention-bot
Copy link

@jmsdvl, thanks for your PR! By analyzing the history of the files in this pull request, we identified @birkenfeld, @freddrake and @serhiy-storchaka to be potential reviewers.

@ghost ghost changed the title fixes: _synthesize called register with the wrong signature trivial-fixes: _synthesize called register with the wrong signature Jul 13, 2017
@ghost ghost changed the title trivial-fixes: _synthesize called register with the wrong signature bpo-31014 webbrowser._synthesize calls webbrowser.register with outdated signature Jul 24, 2017
@@ -113,7 +113,7 @@ def _synthesize(browser, update_tryorder=1):
controller = copy.copy(controller)
controller.name = browser
controller.basename = os.path.basename(browser)
register(browser, None, controller, update_tryorder)
register(browser, None, instance=controller, preferred=update_tryorder)
Copy link
Member

@serhiy-storchaka serhiy-storchaka Jul 24, 2017

Choose a reason for hiding this comment

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

update_tryorder is 1 or -1. preferred is a boolean parameter. 1 and -1 both are true in boolean context.

I think that the update_tryorder parameter of _synthesize() should be replaced with boolean preferred as in register() (see bpo-24241).

Copy link
Author

Choose a reason for hiding this comment

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

Update tryorder is now a boolean as requested.

@serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error and removed CLA not signed labels Jul 24, 2017
@brettcannon
Copy link
Member

To try and help move older pull requests forward, we are going through and backfilling 'awaiting' labels on pull requests that are lacking the label. Based on the current reviews, the best we can tell in an automated fashion is that a core developer requested changes to be made to this pull request.

If/when the requested changes have been made, please leave a comment that says, I have made the requested changes; please review again. That will trigger a bot to flag this pull request as ready for a follow-up review.

@@ -113,7 +113,7 @@ def _synthesize(browser, update_tryorder=1):
controller = copy.copy(controller)
controller.name = browser
controller.basename = os.path.basename(browser)
register(browser, None, controller, update_tryorder)
register(browser, None, instance=controller, preferred=update_tryorder)
Copy link
Author

Choose a reason for hiding this comment

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

Update tryorder is now a boolean as requested.

@@ -265,6 +267,23 @@ def test_register_default(self):
def test_register_preferred(self):
self._check_registration(preferred=True)

def test_environment_variable_BROWSER_is_respected(self):
Copy link
Author

Choose a reason for hiding this comment

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

This test does accurately catch the regression as far as I can tell but it seems a little obscure. Thoughts?

@ghost
Copy link
Author

ghost commented Apr 5, 2018

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@serhiy-storchaka: please review the changes made to this pull request.

@serhiy-storchaka serhiy-storchaka self-assigned this May 13, 2018
@serhiy-storchaka serhiy-storchaka changed the title bpo-31014 webbrowser._synthesize calls webbrowser.register with outdated signature bpo-31014: webbrowser._synthesize calls webbrowser.register with outdated signature May 13, 2018
@serhiy-storchaka
Copy link
Member

I tried to write a less obscure test for the bug in register_standard_browsers(), but failed. But I think we can use simpler test for the original bug in _synthesize().

    def test_synthesize(self):
        webbrowser = support.import_fresh_module('webbrowser')
        name = os.path.basename(sys.executable).lower()
        webbrowser.register(name, None, webbrowser.GenericBrowser(name))
        webbrowser.get(sys.executable)

def mock_which(path):
return True

class Test(test_webbrowser.ImportTest):
Copy link
Contributor

Choose a reason for hiding this comment

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

I almost missed that this re-ran the ImportTest suite with BROWSER set.

I think that's OK as a test case, but it would be clearer as part of a dedicated BrowserOverrideTest class that's placed after ImportTest (and mentions in a class level comment that it re-runs the ImportTest cases in a subprocess with BROWSER set.

@serhiy-storchaka
Copy link
Member

Merged as #7267 with other tests.

@serhiy-storchaka serhiy-storchaka removed their assignment Dec 5, 2018
benjaminp pushed a commit that referenced this pull request Sep 11, 2019
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 11, 2019
Co-Authored-By: Makdon <[email protected]>
(cherry picked from commit e6557d3)

Co-authored-by: Xtreak <[email protected]>
miss-islington added a commit that referenced this pull request Sep 11, 2019
Co-Authored-By: Makdon <[email protected]>
(cherry picked from commit e6557d3)

Co-authored-by: Xtreak <[email protected]>
DinoV pushed a commit to DinoV/cpython that referenced this pull request Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting change review type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants