Hi, I recently realised one can use immutable default arguments to avoid a chain of:

def append_to(element, to=None):
    if to is None:
        to = []

at the beginning of each function with default argument for set, list, or dict.

  • Narann@jlai.lu
    link
    fedilink
    English
    arrow-up
    0
    ·
    9 days ago

    Does not seems to work on 3.12:

    Python 3.12.11 (main, Jun 29 2025, 16:18:35) [MSC v.1944 64 bit (AMD64)] on win32
    >>> def toto(tata=>[]):
      File "<stdin>", line 1
        def toto(tata=>[]):
                      ^
    SyntaxError: invalid syntax