1. 8

  2. 7

    Linking a JSON file might not be the best medium to share.

    1. 3

      You must be trying to look at this on mobile. It’s linked to a Jupyter notebook which renders on desktop in the GitHub UI.

      1. 1

        Ha that’s right!

    2. 1

      tl;dr: Attaching a decorator @deco to foo’s definition is semantically equivalent to writing foo = deco(foo) after foo‘s definition. Multiple decorators attached to the same definition are applied in the reverse order in which they appear in the program text. The consequences of these two facts are exactly what you would expect if you already know the remainder of Python’s syntax and semantics.

      1. 1

        True, but the article also makes the (harder!) case that using decorators in “creative” ways may not actually be a bad idea in all cases. I found it worth reading for that reason.

        1. 1

          The article doesn’t make a very good case. The most “creative” snippets (22 and 23) are also the ugliest ones.

          1. 2

            One good example of a “creative” decorator is in the contextlib package: @contextmanager takes a function and returns a callable object.