Skip to content

Libdoc doesn't handle parameterized types like list[int] properly #4538

Closed

Activity

  1. added this to the v6.0.2 milestone on Nov 18, 2022
  2. self-assigned this
    on Nov 18, 2022
  3. pekkaklarck commented on Nov 18, 2022

    @pekkaklarck
    Member

    It seems that if you have a parameterized type like List[Permission], there's type info only for the top level type. We definitely should show type info also for those nested types. Unfortunately fixing this is likely going to be somewhat complicated and most likely requires updating Libdoc spec files. It's possible that changes are too big for a bug fix release like 6.0.2, but this certainly needs to be fixed latest in 6.1.

  4. Snooz82 commented on Nov 18, 2022

    @Snooz82
    MemberAuthor

    I think it is just an issue of libdoc html

  5. pekkaklarck commented on Nov 18, 2022

    @pekkaklarck
    Member

    Are you sure? I think we only add something like 'list[int]' to the spec. We should list nested types separately.

  6. pekkaklarck commented on Jan 4, 2023

    @pekkaklarck
    Member

    I looked at this a bit more closely and it seems that bigger changes are needed to fix this. I tested this with a library having these two keywords:

    def parameterized(arg: list[int]):
        pass
    
    def union(arg: str|int):
        pass

    The parameterized example demonstrates this issue and yields the following argument information in a generated JSON spec file that also Libdoc's HTML outputs use internally:

          "args": [
            {
              "name": "arg",
              "types": [
                "list[int]"
              ],
              "typedocs": {
                "list[int]": "list"
              },
              "defaultValue": null,
              "kind": "POSITIONAL_OR_NAMED",
              "required": true,
              "repr": "arg: list[int]"
            }
          ]

    The union example works fine and produces this result:

          "args": [
            {
              "name": "arg",
              "types": [
                "str",
                "int"
              ],
              "typedocs": {
                "str": "string",
                "int": "integer"
              },
              "defaultValue": null,
              "kind": "POSITIONAL_OR_NAMED",
              "required": true,
              "repr": "arg: str | int"
            }
          ],

    As you can see, in the union example types are listed separately ("types": ["str", "int"]) and thus they can be easily formatted separately in Libdoc's HTML output as well. In the parameterized example we only get "types": ["list[int]"] and needed to parse that using Javascript to be able to separate the root type list from the nested type int. That's doable but not easy, because there could be multiple levels of nesting. More importantly, all Libdoc spec consumers needed to do same parsing which doesn't make much sense.

    A better solution is separating the root type from nested types already in Libdoc specs. In JSON we could represent list[int], for example, like "types": [["list", "int"]]. With more nesting levels like tuple[list[int], tuple[str, str]] we'd then get "types": [["tuple", ["list", "int"], ["tuple", "str", "str"]]]. I haven't yet looked how this could work in XML but I'm certain we can come up with something.

    A problem with fixing this by enhancing spec files is that such changes to spec files are backwards incompatible and cannot be done in RF 6.0.2. It's a bit questionable to do that in RF 6.1 as well, but because this is a bug fix and occurs only in pretty rare cases I consider it fine. We obviously could change 6.1 to 7.0 to avoid that issue, but I don't think that makes much sense only because of this issue.

  7. modified the milestones: v6.0.2, v6.1 on Jan 4, 2023
  8. pekkaklarck commented on Jan 4, 2023

    @pekkaklarck
    Member

    This issue wasn't relevant before RF 6.0 because earlier nested types weren't taken into account and list[int] was interpreted exactly as list. This was changed by #4433.

  9. changed the title [-]Libdoc html has missing Type Modal when having combined Types like `List[Permission]`[/-] [+]Libdoc doesn't handle parameterized types like `list[Permission]` properly[/+] on Jan 4, 2023
  10. changed the title [-]Libdoc doesn't handle parameterized types like `list[Permission]` properly[/-] [+]Libdoc doesn't handle parameterized types like `list[int]` properly[/+] on Jan 4, 2023
  11. 5 remaining items

  12. pekkaklarck commented on Feb 28, 2023

    @pekkaklarck
    Member

    I knew this issue requires quite a bit of changes, but it turned out to be an even bigger task than I anticipated. Good news is that the problem is now finally fixed. JSON and XML specs have been updated as I proposed above, and HTML output now shows parameterized types so that both the top level type and nested types are links to type information.

    As part of updating HTML output, I changed normal types so that they are shown like int instead of <int>. The reason was that with parameterized types list[int] looks considerably better than <list>[<int>] and it's more consistent to avoid angle brackets altogether. I also changed unions so that they are shown like int | float instead of <int> or <float>. The main reason to use | instead of or was that I wanted the syntax to look more like Python syntax. I also prefer list[int | float] over list[int or float] (or <list>[<int> or <float>].

    I would have wanted to use exactly list[int] style with parameterized types, but our current templating system doesn't make that easy and currently the format is list [ int ]. These space are unnecessary but not too distracting. A bit worse situation is that if there are multiple nested types like dict[str, int], the format is dict [ str , int ] i.e. there's an extra space also before the comma. Having more than one nested type is relatively rare, and the extra space isn't that bad, so perhaps we can live with that as well.

    What do others think, should we try to enhance HTML outputs still or are they good enough for now? I'd kind of like to get those extra spaces removed, but then again I wouldn't like to spend much time for this and would rather investigate better Libdoc HTML tech (#4304). How do you feel about using int instead of <int> and int | float instead of <int> or <float>?

    I leave this issue open in case someone is interested to enhance HTML outputs still. @mkorpela made big changes some time ago, and it would be great if you'd be interested to take another look at this. @Snooz82 and @samipe may also be interested in this.

  13. pekkaklarck commented on Feb 28, 2023

    @pekkaklarck
    Member

    As an example how this feature works, I tested the following keyword:

    def kw(a: int,
           b: int|float,
           c: list[int],
           d: dict[str, int],
           e: list[int|float|str],
           f: tuple[tuple[int], tuple[int|float]]):
        pass

    This is how HTML documentation looks like:

    As a reference, this is how it looked earlier:

    In my opinion the current output looks better than earlier in general, and obviously now all nested types are links, but I'm certain it could still be enhanced.

  14. pekkaklarck commented on Mar 10, 2023

    @pekkaklarck
    Member

    No comments about the styles so I consider the current output good enough for RF 6.1 close this issue. It's still possible to enhance output both before and after the release, though.

  15. added theissue type on Dec 9, 2025
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

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions