Remix.run Logo
mdaniel 3 days ago

"beautiful" is a bit of a stretch. I am completely open to the fact that doing it in a Pythonic way would make the grammar angry but things have gone off the rails when one needs to introduce a 2nd assignment operator into a language

  if ma = re.search(needle, haystack):
      print("ok, things are sane")
I cannot think of a stellar reason why assignment shouldn't be an expression in sane languages. While digging up the grammar[1] I was also reminded that walrus is seemingly incompatible with type annotations, too

  >>> if (x: str := re.sub("a", "b", "abc")):
    File "<python-input-8>", line 1
      if (x: str := re.sub("a", "b", "abc")):
         ^
  SyntaxError: invalid syntax
Also, you say "temporary variable" but it's no more temporary than any other local variable, because lexical scoping is evidently for children

I have always hated that comprehension variables leak for that same reason

1: https://github.com/python/cpython/blob/v3.13.7/Grammar/pytho...