This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Document the `controller.name` field in `webbrowser` module
Type: enhancement Stage: patch review
Components: Documentation, Library (Lib) Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: corona10, docs@python, ilyagr, sobolevn, terry.reedy, zach.ware
Priority: normal Keywords: patch

Created on 2021-03-07 01:38 by ilyagr, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 30241 merged sobolevn, 2021-12-23 11:41
Messages (5)
msg388218 - (view) Author: Ilya Grigoriev (ilyagr) Date: 2021-03-07 01:38
The object `webbrowser.get()` returns has, and had for a long time, a useful but undocumented field `name`. I wonder if it would be OK to document it as something like `a system-dependent name for the browser`. This would go here:

https://docs.python.org/3/library/webbrowser.html#browser-controller-objects

The reason I'd like this is so that I can write code like the following:

```python
# In Crostini Chrome OS Linux, the default browser is set to an
# intermediary called `garcon-url-handler`.
# It opens URLs in Chrome running outside the linux VM. This 
# browser does not have access to the Linux filesystem. Some references:
# https://chromium.googlesource.com/chromiumos/platform2/+/master/vm_tools/garcon/#opening-urls
# https://source.chromium.org/search?q=garcon-url-handler

if "garcon-url-handler" in webbrowser.get().name:
  webbrowser.open("http://external-url.com/docs.html")
else:
  webbrowser.open("file:///usr/share/doc/docs.html")
```

This would work correctly, even if the user has installed a browser native to the Linux VM and put it into their `BROWSER` environment variable. I don't know a better way to achieve the same effect.

Some references to where the `name` field was introduced:

https://bugs.python.org/issue754022

https://github.com/python/cpython/commit/e8f244305ef4f257f6999b69601f4316b31faa5e
msg408996 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-12-21 09:59
Zach, gaurawgoshwami is a spammer. Deleted added nosy, unlinked spam file and unrelated PR.  I have no idea what 'repository containing patch' means or how g. created link to non-existent? file.
msg409087 - (view) Author: Nikita Sobolev (sobolevn) * (Python triager) Date: 2021-12-23 11:10
Hm, looks like `.name` does not exist for `MacOSXOSAScript`:

```
Python 3.11.0a3+ (heads/main-dirty:71ef0b4c2b, Dec 23 2021, 12:38:09) [Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import webbrowser
>>> webbrowser.get()
<webbrowser.MacOSXOSAScript object at 0x105a75500>
>>> a = webbrowser.get()
>>> dir(a)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_name', 'args', 'open', 'open_new', 'open_new_tab']
>>> a.name
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'MacOSXOSAScript' object has no attribute 'name'. Did you mean: '_name'?
```

This happens because `MacOSXOSAScript` does not call `super().__init__()` in any way, nor it defines `name` and `basename` attributes.

It has this API for 12 years now: https://github.com/python/cpython/commit/4d39f6e09a5c0a0e09eb51d678bacd1adaa3f2ca

So, I see two possible ways to solve this:
1. Ensure all subtypes of `BaseBrowser` to have `name` and `basename` (because they are defined in `BaseBrowser`) and document them
2. Add a code comment that they are just implementation details and not a part of the public API
msg409342 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-12-30 01:30
New changeset d12bec69931503be78cd555cf7bc22ad6f4f2bd5 by Nikita Sobolev in branch 'main':
bpo-43424: Deprecate `webbrowser.MacOSXOSAScript._name` attribute (GH-30241)
https://github.com/python/cpython/commit/d12bec69931503be78cd555cf7bc22ad6f4f2bd5
msg409344 - (view) Author: Ilya Grigoriev (ilyagr) Date: 2021-12-30 02:27
Thank you very much, Nikita! Your patch would certainly solve my issue.

As is, I checked the code I wrote, and it seems that only a lucky
ordering of if-statements caused it to work on Macs.

Ilya.

On Wed, Dec 29, 2021 at 5:30 PM Dong-hee Na <report@bugs.python.org> wrote:
>
>
> Dong-hee Na <donghee.na@python.org> added the comment:
>
>
> New changeset d12bec69931503be78cd555cf7bc22ad6f4f2bd5 by Nikita Sobolev in branch 'main':
> bpo-43424: Deprecate `webbrowser.MacOSXOSAScript._name` attribute (GH-30241)
> https://github.com/python/cpython/commit/d12bec69931503be78cd555cf7bc22ad6f4f2bd5
>
>
> ----------
> nosy: +corona10
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue43424>
> _______________________________________
History
Date User Action Args
2022-04-11 14:59:42adminsetgithub: 87590
2021-12-30 02:27:21ilyagrsetmessages: + msg409344
2021-12-30 01:30:17corona10setnosy: + corona10
messages: + msg409342
2021-12-23 12:00:07AlexWaygoodsettype: security -> enhancement
versions: + Python 3.11, - Python 3.10
2021-12-23 11:41:02sobolevnsetpull_requests: + pull_request28463
2021-12-23 11:10:40sobolevnsetnosy: + sobolevn
messages: + msg409087
2021-12-21 13:49:02zach.waresethgrepos: - hgrepo413
2021-12-21 09:59:44terry.reedysetnosy: - barry, paul.moore, ronaldoussoren, vstinner, tim.golden, ned.deily, ezio.melotti, eric.araujo, mrabarnett, r.david.murray, asvetlov, yselivanov, koobs, steve.dower, dstufft, lys.nikolaou, pablogsal, gaurawgoshwami
messages: + msg408996
2021-12-21 09:56:04terry.reedysetpull_requests: - pull_request28440
2021-12-21 09:54:08terry.reedysetfiles: - images (5).jpeg
2021-12-21 09:52:04terry.reedysetmessages: - msg408987
2021-12-21 08:26:43Alex.Willmersetnosy: - Alex.Willmer
2021-12-21 07:46:43larrysetnosy: - larry
components: + Documentation
2021-12-21 07:46:08larrysetcomponents: + Library (Lib), - Argument Clinic
2021-12-21 07:45:50larrysetnosy: barry, terry.reedy, paul.moore, ronaldoussoren, vstinner, larry, tim.golden, ned.deily, ezio.melotti, eric.araujo, mrabarnett, r.david.murray, asvetlov, docs@python, zach.ware, yselivanov, koobs, steve.dower, dstufft, Alex.Willmer, lys.nikolaou, pablogsal, ilyagr, gaurawgoshwami
components: - Build, Demos and Tools, Distutils, Documentation, Extension Modules, IDLE, Installation, Interpreter Core, Library (Lib), macOS, Regular Expressions, Tests, Tkinter, Unicode, Windows, XML, 2to3 (2.x to 3.x conversion tool), ctypes, IO, Cross-Build, email, asyncio, FreeBSD, SSL, C API, Subinterpreters, Parser
2021-12-21 07:13:42gaurawgoshwamisetfiles: + images (5).jpeg


hgrepos: + hgrepo413
keywords: + patch
stage: patch review
nosy: + terry.reedy, larry, paul.moore, pablogsal, dstufft, asvetlov, eric.araujo, koobs, yselivanov, gaurawgoshwami, zach.ware, steve.dower, ned.deily, barry, Alex.Willmer, ezio.melotti, ronaldoussoren, lys.nikolaou, r.david.murray, vstinner, tim.golden, mrabarnett
messages: + msg408987
pull_requests: + pull_request28440
components: + Build, Demos and Tools, Distutils, Extension Modules, IDLE, Installation, Interpreter Core, macOS, Regular Expressions, Tests, Tkinter, Unicode, Windows, XML, 2to3 (2.x to 3.x conversion tool), ctypes, IO, Cross-Build, email, asyncio, Argument Clinic, FreeBSD, SSL, C API, Subinterpreters, Parser
type: enhancement -> security
2021-03-07 01:38:28ilyagrcreate