You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Libdoc doesn't handle parameterized types like list[int] properly #4538
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.
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:
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.
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.
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
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
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.
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.
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.
Activity
pekkaklarck commentedon Nov 18, 2022
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.Snooz82 commentedon Nov 18, 2022
I think it is just an issue of libdoc html
pekkaklarck commentedon Nov 18, 2022
Are you sure? I think we only add something like
'list[int]'to the spec. We should list nested types separately.pekkaklarck commentedon Jan 4, 2023
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:
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:
The union example works fine and produces this result:
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 typelistfrom the nested typeint. 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 liketuple[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.
pekkaklarck commentedon Jan 4, 2023
This issue wasn't relevant before RF 6.0 because earlier nested types weren't taken into account and
list[int]was interpreted exactly aslist. This was changed by #4433.[-]Libdoc html has missing Type Modal when having combined Types like `List[Permission]`[/-][+]Libdoc doesn't handle parameterized types like `list[Permission]` properly[/+][-]Libdoc doesn't handle parameterized types like `list[Permission]` properly[/-][+]Libdoc doesn't handle parameterized types like `list[int]` properly[/+]5 remaining items
Libdoc backwards compatibility tests.
Libdoc: Show parameterized types properly in HTML #4538
pekkaklarck commentedon Feb 28, 2023
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
intinstead of<int>. The reason was that with parameterized typeslist[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 likeint | floatinstead of<int> or <float>. The main reason to use|instead oforwas that I wanted the syntax to look more like Python syntax. I also preferlist[int | float]overlist[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 islist [ int ]. These space are unnecessary but not too distracting. A bit worse situation is that if there are multiple nested types likedict[str, int], the format isdict [ 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
intinstead of<int>andint | floatinstead 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.
pekkaklarck commentedon Feb 28, 2023
As an example how this feature works, I tested the following keyword:
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.
pekkaklarck commentedon Mar 10, 2023
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.
Libdoc: Properly support parametrized types like list[int].
Libdoc backwards compatibility tests.
Libdoc: Show parameterized types properly in HTML #4538
Remove last deprecated items fron Libdoc specs.