• dormedas
    link
    fedilink
    arrow-up
    43
    arrow-down
    2
    ·
    3 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
      17
      ·
      edit-2
      3 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.

      • scott@lemmy.org
        link
        fedilink
        English
        arrow-up
        1
        arrow-down
        1
        ·
        3 days ago

        Lemme golf that

        ~ $ python
        Python 3.12.10 (main, Apr  9 2025, 18:13:11) [Clang 18.0.3 (https://android.googlesource.com/toolchain/llvm-project d8003a456 on linux
        Type "help", "copyright", "credits" or "license" for more information.
        >>> class x:
        ...  def __repr__(s):
        ...   exit(0)
        ...
        >>> xit = x()
        >>> xit
        ~ $
        

        Not that hard

        • brian@programming.dev
          link
          fedilink
          arrow-up
          5
          ·
          2 days ago

          repr is generally assumed to be side effect free and cheap to run, so things like debuggers tend to show repr of things in scope, including possibly exit

          also then it behaves differently between repl and script, since repr never gets run. to do it properly it has to be a new repl keyword I imagine, but I still don’t know if I’m sold on the idea

          • scott@lemmy.org
            link
            fedilink
            English
            arrow-up
            3
            ·
            2 days ago

            Good points. You’re right, it does need solved at the shell level. Glad they did so.