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

Document the controller.name field in webbrowser module #87590

Closed
ilyagr mannequin opened this issue Mar 7, 2021 · 5 comments
Closed

Document the controller.name field in webbrowser module #87590

ilyagr mannequin opened this issue Mar 7, 2021 · 5 comments
Labels
3.11 only security fixes docs Documentation in the Doc dir stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ilyagr
Copy link
Mannequin

ilyagr mannequin commented Mar 7, 2021

BPO 43424
Nosy @terryjreedy, @zware, @corona10, @sobolevn
PRs
  • bpo-43424: Deprecate webbrowser.MacOSXOSAScript._name attribute #30241
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2021-03-07.01:38:28.573>
    labels = ['3.11', 'type-feature', 'library', 'docs']
    title = 'Document the `controller.name` field in `webbrowser` module'
    updated_at = <Date 2021-12-30.02:27:21.891>
    user = 'https://bugs.python.org/ilyagr'

    bugs.python.org fields:

    activity = <Date 2021-12-30.02:27:21.891>
    actor = 'ilyagr'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation', 'Library (Lib)']
    creation = <Date 2021-03-07.01:38:28.573>
    creator = 'ilyagr'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43424
    keywords = ['patch']
    message_count = 5.0
    messages = ['388218', '408996', '409087', '409342', '409344']
    nosy_count = 6.0
    nosy_names = ['terry.reedy', 'docs@python', 'zach.ware', 'corona10', 'sobolevn', 'ilyagr']
    pr_nums = ['30241']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue43424'
    versions = ['Python 3.11']

    @ilyagr
    Copy link
    Mannequin Author

    ilyagr mannequin commented Mar 7, 2021

    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:

    # 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

    e8f2443

    @ilyagr ilyagr mannequin added type-feature A feature request or enhancement docs Documentation in the Doc dir stdlib Python modules in the Lib dir 3.10 only security fixes labels Mar 7, 2021
    @ilyagr ilyagr mannequin assigned docspython Mar 7, 2021
    @ilyagr ilyagr mannequin added type-feature A feature request or enhancement docs Documentation in the Doc dir stdlib Python modules in the Lib dir 3.10 only security fixes labels Mar 7, 2021
    @larryhastings larryhastings added stdlib Python modules in the Lib dir docs Documentation in the Doc dir and removed topic-IO topic-subinterpreters interpreter-core (Objects, Python, Grammar, and Parser dirs) build The build process and cross-build topic-email topic-asyncio topic-SSL topic-C-API topic-argument-clinic labels Dec 21, 2021
    @terryjreedy
    Copy link
    Member

    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.

    @sobolevn
    Copy link
    Member

    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: 4d39f6e

    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

    @AlexWaygood AlexWaygood added 3.11 only security fixes type-feature A feature request or enhancement and removed 3.10 only security fixes type-security A security issue labels Dec 23, 2021
    @corona10
    Copy link
    Member

    New changeset d12bec6 by Nikita Sobolev in branch 'main':
    bpo-43424: Deprecate webbrowser.MacOSXOSAScript._name attribute (GH-30241)
    d12bec6

    @ilyagr
    Copy link
    Mannequin Author

    ilyagr mannequin commented Dec 30, 2021

    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 d12bec6 by Nikita Sobolev in branch 'main':
    bpo-43424: Deprecate webbrowser.MacOSXOSAScript._name attribute (GH-30241)
    d12bec6

    ----------
    nosy: +corona10


    Python tracker <report@bugs.python.org>
    <https://bugs.python.org/issue43424\>


    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @slateny slateny closed this as completed May 15, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes docs Documentation in the Doc dir stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    6 participants