[Python-checkins] bpo-43424: Deprecate `webbrowser.MacOSXOSAScript._name` attribute (GH-30241)
corona10
webhook-mailer at python.org
Wed Dec 29 20:30:18 EST 2021
https://github.com/python/cpython/commit/d12bec69931503be78cd555cf7bc22ad6f4f2bd5
commit: d12bec69931503be78cd555cf7bc22ad6f4f2bd5
branch: main
author: Nikita Sobolev <mail at sobolevn.me>
committer: corona10 <donghee.na92 at gmail.com>
date: 2021-12-30T10:30:13+09:00
summary:
bpo-43424: Deprecate `webbrowser.MacOSXOSAScript._name` attribute (GH-30241)
files:
A Misc/NEWS.d/next/Library/2021-12-23-14-36-58.bpo-43424.d9x2JZ.rst
M Doc/library/webbrowser.rst
M Lib/test/test_webbrowser.py
M Lib/webbrowser.py
diff --git a/Doc/library/webbrowser.rst b/Doc/library/webbrowser.rst
index 19b3c463bb817..1dc59306164ec 100644
--- a/Doc/library/webbrowser.rst
+++ b/Doc/library/webbrowser.rst
@@ -197,6 +197,11 @@ Browser controllers provide these methods which parallel three of the
module-level convenience functions:
+.. attribute:: name
+
+ System-dependent name for the browser.
+
+
.. method:: controller.open(url, new=0, autoraise=True)
Display *url* using the browser handled by this controller. If *new* is 1, a new
diff --git a/Lib/test/test_webbrowser.py b/Lib/test/test_webbrowser.py
index 673cc995d3f5a..dbfd2e5a0f280 100644
--- a/Lib/test/test_webbrowser.py
+++ b/Lib/test/test_webbrowser.py
@@ -304,7 +304,7 @@ def test_environment(self):
webbrowser = import_helper.import_fresh_module('webbrowser')
try:
browser = webbrowser.get().name
- except (webbrowser.Error, AttributeError) as err:
+ except webbrowser.Error as err:
self.skipTest(str(err))
with os_helper.EnvironmentVarGuard() as env:
env["BROWSER"] = browser
@@ -316,7 +316,7 @@ def test_environment_preferred(self):
try:
webbrowser.get()
least_preferred_browser = webbrowser.get(webbrowser._tryorder[-1]).name
- except (webbrowser.Error, AttributeError, IndexError) as err:
+ except (webbrowser.Error, IndexError) as err:
self.skipTest(str(err))
with os_helper.EnvironmentVarGuard() as env:
diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py
index 3244f206aade6..02d2036906178 100755
--- a/Lib/webbrowser.py
+++ b/Lib/webbrowser.py
@@ -666,19 +666,33 @@ def open(self, url, new=0, autoraise=True):
return not rc
class MacOSXOSAScript(BaseBrowser):
- def __init__(self, name):
- self._name = name
+ def __init__(self, name='default'):
+ super().__init__(name)
+
+ @property
+ def _name(self):
+ warnings.warn(f'{self.__class__.__name__}._name is deprecated in 3.11'
+ f' use {self.__class__.__name__}.name instead.',
+ DeprecationWarning, stacklevel=2)
+ return self.name
+
+ @_name.setter
+ def _name(self, val):
+ warnings.warn(f'{self.__class__.__name__}._name is deprecated in 3.11'
+ f' use {self.__class__.__name__}.name instead.',
+ DeprecationWarning, stacklevel=2)
+ self.name = val
def open(self, url, new=0, autoraise=True):
- if self._name == 'default':
+ if self.name == 'default':
script = 'open location "%s"' % url.replace('"', '%22') # opens in default browser
else:
- script = '''
+ script = f'''
tell application "%s"
activate
open location "%s"
end
- '''%(self._name, url.replace('"', '%22'))
+ '''%(self.name, url.replace('"', '%22'))
osapipe = os.popen("osascript", "w")
if osapipe is None:
diff --git a/Misc/NEWS.d/next/Library/2021-12-23-14-36-58.bpo-43424.d9x2JZ.rst b/Misc/NEWS.d/next/Library/2021-12-23-14-36-58.bpo-43424.d9x2JZ.rst
new file mode 100644
index 0000000000000..aa5f8d4211c37
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-12-23-14-36-58.bpo-43424.d9x2JZ.rst
@@ -0,0 +1 @@
+Deprecate :attr:`webbrowser.MacOSXOSAScript._name` and use ``name`` instead.
More information about the Python-checkins
mailing list