• dormedas@lemmy.dormedas.com
      link
      fedilink
      arrow-up
      2
      ·
      12 days ago

      FINALLY! This has always annoyed me. If you’re gonna go through all the trouble of identifying that I want to exit, just DO it.

      • wise_pancake@lemmy.ca
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        12 days ago

        It’s not really much extra effort though

        They just added so e text to the __repr__ method on the exit callable object

        That’s much easier than figuring out if your running this interactively and trying to figure out if this is going to break stuff.

  • RapidCatLauncher@lemmy.ca
    link
    fedilink
    English
    arrow-up
    2
    ·
    12 days ago

    That just gave me the idea that it would be fun to inspect exit a little.

    Which led me down this path:

    >>> repr(exit)
    'Use exit() or Ctrl-Z plus Return to exit'
    >>> dir(exit)
    [(...), 'eof', 'name']
    >>> exit.eof, exit.name
    ('Ctrl-Z plus Return', 'exit')
    

    Okay, cool, the “Use exit() etc.” blurb appears because it’s the function’s repr, and the string is assembled from its name and eof properties.

    Now let’s try to make our own:

    >>> exit.__class__
    <class '_sitebuiltins.Quitter'>
    >>> gtfo = exit.__class__()
    TypeError: Quitter.__init__() missing 2 required positional arguments: 'name' and 'eof'
    

    Oh Python, you shouldn’t have.

    >>> gtfo = exit.__class__("a big puff of smoke", "a sneaky skedaddle")
    >>> gtfo
    Use a big puff of smoke() or a sneaky skedaddle to exit
    

    Beauty!