GNU social JP
  • FAQ
  • Login
GNU social JPは日本のGNU socialサーバーです。
Usage/ToS/admin/test/Pleroma FE
  • Public

    • Public
    • Network
    • Groups
    • Featured
    • Popular
    • People

Conversation

Notices

  1. Embed this notice
    ✧✦Catherine✦✧ (whitequark@mastodon.social)'s status on Monday, 21-Apr-2025 08:42:31 JST ✧✦Catherine✦✧ ✧✦Catherine✦✧

    python 3.12 match statement makes it really easy to write ad-hoc option parsers with state machines

    In conversation about a month ago from mastodon.social permalink

    Attachments


    1. https://files.mastodon.social/media_attachments/files/114/372/936/135/717/118/original/c98763bf501ae79f.png
    • clacke and clacke at libranet.de is my main like this.
    • Embed this notice
      ✧✦Catherine✦✧ (whitequark@mastodon.social)'s status on Monday, 21-Apr-2025 08:50:11 JST ✧✦Catherine✦✧ ✧✦Catherine✦✧
      in reply to

      yes yes i fucked up. this needs a while loop or something

      In conversation about a month ago permalink
    • Embed this notice
      Helge Heß (helge@mastodon.social)'s status on Monday, 21-Apr-2025 08:58:44 JST Helge Heß Helge Heß
      in reply to

      @whitequark Looks like Swift, except in Swift, you rather link a 6MB big argument-parser lib that statically types out all the possible options 🙈
      (but really, the `match` looks like how Swift's `switch` works)

      In conversation about a month ago permalink
    • Embed this notice
      ✧✦Catherine✦✧ (whitequark@mastodon.social)'s status on Monday, 21-Apr-2025 09:06:00 JST ✧✦Catherine✦✧ ✧✦Catherine✦✧
      in reply to
      • Simon Sapin

      @simon ... excellent idea

      In conversation about a month ago permalink
    • Embed this notice
      Simon Sapin (simon@tutut.delire.party)'s status on Monday, 21-Apr-2025 09:06:02 JST Simon Sapin Simon Sapin
      in reply to

      @whitequark or name the iterator and call next() on it for --triple?

      In conversation about a month ago permalink
    • Embed this notice
      ✧✦Catherine✦✧ (whitequark@mastodon.social)'s status on Monday, 21-Apr-2025 09:06:15 JST ✧✦Catherine✦✧ ✧✦Catherine✦✧
      in reply to
      • Simon Sapin

      @simon actually no that won't work because you need lookahead

      In conversation about a month ago permalink
    • Embed this notice
      ✧✦Catherine✦✧ (whitequark@mastodon.social)'s status on Monday, 21-Apr-2025 09:06:56 JST ✧✦Catherine✦✧ ✧✦Catherine✦✧
      in reply to
      • Helge Heß

      @helge or Rust! yeah

      In conversation about a month ago permalink
    • Embed this notice
      poleguy (poleguy@mastodon.social)'s status on Monday, 21-Apr-2025 11:52:17 JST poleguy poleguy
      in reply to

      @whitequark I just use typer. Good enough.

      In conversation about a month ago permalink
    • Embed this notice
      dram🎀 (dramforever@mastodon.social)'s status on Sunday, 27-Apr-2025 02:19:18 JST dram🎀 dram🎀
      in reply to

      @whitequark i had an idea... and yup

      while True:
      match args:
      case [ '--foo', foo, *args ]:
      print('foo', foo)
      case [ '--baz', *args ]:
      print('baz')
      case [ '--', *args ]:
      break
      case [ arg, *args ] if arg.startswith('-'):
      print('Unrecognized', arg)
      raise RuntimeError() # FIXME

      # This can't be case _:
      # Otherwise previous case overwrites args
      case args:
      break

      In conversation about a month ago permalink
      clacke likes this.
    • Embed this notice
      ✧✦Catherine✦✧ (whitequark@mastodon.social)'s status on Sunday, 27-Apr-2025 05:37:18 JST ✧✦Catherine✦✧ ✧✦Catherine✦✧
      in reply to
      • dram🎀

      @dramforever oh this is cute

      In conversation about a month ago permalink
    • Embed this notice
      dram🎀 (dramforever@mastodon.social)'s status on Sunday, 27-Apr-2025 05:37:19 JST dram🎀 dram🎀
      in reply to

      @whitequark now i wonder if you can subclass list to make it not quadratic

      In conversation about a month ago permalink
    • Embed this notice
      Simon Sapin (simon@tutut.delire.party)'s status on Sunday, 27-Apr-2025 16:00:12 JST Simon Sapin Simon Sapin
      in reply to

      @whitequark wow i didn’t know modern python could be this nice
      (shouldn’t `--triple something` consume two arguments though?)

      In conversation about a month ago permalink
      clacke likes this.
    • Embed this notice
      Thomas Guyot-Sionnest (dermoth@noc.social)'s status on Sunday, 27-Apr-2025 16:00:21 JST Thomas Guyot-Sionnest Thomas Guyot-Sionnest
      in reply to

      @whitequark What I really like is matching directly object or property types in the case statements. ex:

      ```python
      match fruit_obj:
      case Apple(color=Red()):
      print("I'm a red apple")
      case Apple():
      print("I'm an apple")
      case Orange():
      print("I'm an orange")
      case _:
      print(f"Unknown fruit type: {type(fruit_obj)}")
      ```

      P.S. match case statements were introduced in 3.10.

      In conversation about a month ago permalink
      clacke likes this.

Feeds

  • Activity Streams
  • RSS 2.0
  • Atom
  • Help
  • About
  • FAQ
  • TOS
  • Privacy
  • Source
  • Version
  • Contact

GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.