[Python] Proper way to document keys in TypedDict?

Discussão em 'Python' iniciado por Stack, Agosto 23, 2025.

  1. Stack

    Stack Membro Participativo

    What is the proper way to document keys inside a TypedDict? I don't see much information inside PEP 589 – TypedDict.

    I can think of a few solutions:


    1. Document keys inside a docstring (is there a standard field to use here?):

      class Foo(TypedDict):
      """
      I am a documented schema.

      Keys:
      key: This key has some implications needing documentation.
      """

      key: int

    2. Document keys using inline comments inside the TypedDict

      class Foo(TypedDict):
      """I am a documented schema."""

      # This key has some implications needing documentation
      key: int

    Is there an official approach to this? Anything specific that Sphinx may look for?

    Continue reading...

Compartilhe esta Página