Skip to content

Libdoc: TypedDicts used as types with other TypedDicts are not automatically documented #5844

Open

Description

@Snooz82

Libdoc documents a type under "Data types" only when it appears in a keyword's argument or return type. It does not look into the fields of a TypedDict. A TypedDict that only appears as a field of another TypedDict is therefore never documented and cannot be linked.

Example from Browser library. Wait For Response returns a CapturedResponse:

class HeaderEntry(TypedDict):
    """One HTTP header, as listed in ``headersArray``."""
    name: str
    value: str

class ServerAddress(TypedDict):
    ipAddress: str
    port: int

class CapturedResponse(TypedDict):
    status: int
    headersArray: list[HeaderEntry]
    serverAddr: ServerAddress | None
    request: CapturedRequest
    ...

CapturedResponse shows up under "Data types". HeaderEntry and ServerAddress do not, even though users need their structure. Two more consequences:

  • In the "Dictionary structure" of CapturedResponse, the field types are plain text without links. The names are also fully qualified: <list[Browser.utils.data_types.HeaderEntry]>.
  • In docstrings, `HeaderEntry` does not become a link, because the type is unknown to Libdoc.

Library authors currently have to repeat the structure of every nested type inline in the docstring of the outer type. Browser does this today.

See in Browser v21.0.0 Keyword Docs in New Context the argument recordVideo as one example.
And see Libdoc PoC with Browser and the New Context keyword with recordVideo argument or the Return Values of Wait For Request and Wait For Response to see how it could work.

Proposal

  1. TypeDocBuilder._yield_infos (robotbuilder.py) also recurses into TypedDictInfo.annotations, with a guard against recursive TypedDicts. Nested TypedDicts, Enums and other types then get documented like argument types, and their usages list the keyword.
  2. TypedDictItem keeps its TypeInfo and serializes it as typeInfo (same shape as an argument's type: name, typedoc, nested, union, alias). The HTML template renders it with the existing renderTypeInfo helper. Field types then become clickable links. Navigation
    between type dialogs, including the back link, already works.
  3. type stays for backwards compatibility. It uses str(TypeInfo), which gives list[HeaderEntry] instead of the module path.

I'm happy to open a PR if this direction is acceptable.

Activity

  1. Snooz82 commented on Nov 2, 2026

    @Snooz82
    MemberAuthor

    Hi @pekkaklarck,

    While working on this I noticed that a recursive TypedDict already fails is 7.5 and earlier, independent of Libdoc.
    A library using it cannot even be imported.

    RecursiveTypedDict.py:

    from typing import TypedDict
    
    
    class Node(TypedDict):
        name: str
        children: "list[Node]"
    
    
    def count_nodes(node: Node) -> int:
        return 1 + sum(count_nodes(child) for child in node["children"])

    test.robot:

    *** Settings ***
    Library    RecursiveTypedDict.py
    
    *** Test Cases ***
    Count
        ${count} =    Count Nodes    {'name': 'root', 'children': []}
        Should Be Equal    ${count}    ${1}

    Libdoc:

    $ libdoc RecursiveTypedDict.py out.html
    Building library 'RecursiveTypedDict.py' failed: RecursionError: maximum recursion depth exceeded
    

    Execution:

    $ robot test.robot
    [ ERROR ] Unexpected error: RecursionError: maximum recursion depth exceeded
    

    With Python 3.9, execution does not crash, but the test fails with RecursionError: maximum recursion depth exceeded while calling a Python object.

    Tested with RF 7.5.1 on Python 3.12 and 3.9, and with current master.

    The recursion happens in TypedDictInfo.__init__. It creates a TypeInfo for every field, so Node -> list[Node] -> Node -> ... never ends:

      File ".../robot/running/arguments/typeinfo.py", line 251, in from_type_hint
        return TypedDictInfo(hint.__name__, hint, alias=alias)
      File ".../robot/running/arguments/typeinfo.py", line 509, in __init__
        name: TypeInfo.from_type_hint(hint) for name, hint in type_hints.items()
      [...]
    RecursionError: maximum recursion depth exceeded
    

    Recursive type aliases are already handled (RecursiveAlias), but recursive TypedDicts are not.
    This can also be fixed in TypedDictInfo.

  2. Snooz82 commented on Nov 2, 2026

    @Snooz82
    MemberAuthor

    While fixing the recursion, I found an existing problem in RecursiveConverter. It was added with recursive type alias support in RF 7.5. When a nested value is invalid, the error message wraps an inner "Argument ... cannot be converted to ..." message at every level of recursion.

    Reproduction (Python 3.12+):

    from robot.running import TypeInfo
    
    type Nested = list[Nested]
    
    TypeInfo.from_type_hint(Nested).convert("[[1]]")

    Current result:

    ValueError: Argument '[[1]]' cannot be converted to Nested: Item '0' got value '[1]' (list) that cannot be converted to Nested: Argument '[1]' (list) cannot be converted to list[Nested]: Item '0' got value '1' (integer) that cannot be converted to Nested: Argument '1' (integer) cannot
    be converted to list[Nested].
    

    RecursiveConverter calls the resolved converter without name and kind. The inner converter therefore produces a complete "Argument ..." message, and the outer converter wraps it a second time. Most recursive aliases are unions, such as JSON. Union converters do not show the
    details of inner errors, which is probably why this has not come up so far. With recursive TypedDicts it would occur on every invalid nested value.

    My fix makes RecursiveConverter pass name and kind to the resolved converter and keep the alias name. The message has no duplicate parts, and nested levels use the same type name as the top level:

    ValueError: Argument '[[1]]' cannot be converted to Nested: Item '0' got value '[1]' (list) that cannot be converted to Nested: Item '0' got value '1' (integer) that cannot be converted to Nested.
    
  3. self-assigned this
    on Nov 2, 2026
  4. pekkaklarck commented on Nov 3, 2026

    @pekkaklarck
    Member

    Plenty of related issues that all look somewhat severe. If I got it right, there are no regressions, though. Nested TypeDicts also apparently work even though Libdoc doesn't handle them too well. The problem with recursive TypedDicts should get its own issue.

    Fixing everything properly is a somewhat big task require plenty of changes. I thus believe it would be better to fix this in RF 7.6 than in RF 7.5.2.

  5. pekkaklarck commented on Nov 18, 2026

    @pekkaklarck
    Member

    Let's concentrate on the documentation issue with nested TypedDicts in this issue. Can you @Snooz82 submit a separate issue about the crash with recursive TypedDicts or should I do that? I believe both of these can wait for RF 7.6.

  6. added this to the v7.6 milestone on Nov 18, 2026
  7. added theissue type on Nov 18, 2026
  8. changed the title [-]Libdoc: document TypedDicts nested in TypedDict items and link item types[/-] [+]Libdoc: TypedDicts used as types with other TypedDicts are not automatically documented[/+] on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions