Skip to content

Libdoc should format argument names, defaults and types differently #3586

Closed

Description

@pekkaklarck

Libdoc shows argument names in format name: type=default (e.g. count: int=1) where both : type and =default are used only when needed. Currently all this is in same font, but adding some styles would be a good idea. If someone has ideas about good styles to use, please tell your ideas in comments or provide a PR!

This is somewhat related to #3578 but because this issue affects only HTML outputs there are no backwards incompatibility concerns. Implementing this already in RF 3.2.2 is thus possible.

Activity

  1. modified the milestones: v3.2.2, v3.3 on May 29, 2020
  2. pekkaklarck commented on Jun 1, 2020

    @pekkaklarck
    MemberAuthor

    Moved to 3.3 scope because:

  3. aaltat commented on Jun 6, 2020

    @aaltat
    Contributor

    Well, I don't have any suggestions for styles, but would it be good idea to look few examples from IDE or how GitHub does colouring for Python type hints. Example GitHub leans to orange with white background and perhaps default values could be bluish. I would lead the argument itself to black.

  4. rasjani commented on Jun 23, 2020

    @rasjani
    Contributor

    Sorry if this is not applicable to this issue but it talked about formatting arguments in libdoc.

    I have type hints like this within my source code:

    def drag_and_drop(self: "SeleniumTestability", locator: LocatorType, target: LocatorType, html5: bool = False) -> None:

    Where LocatorType previously defined as:

    from selenium.webdriver.support.event_firing_webdriver import EventFiringWebElement, EventFiringWebDriver
    LocatorType = Union[WebElementType, EventFiringWebElement, str]

    In the docs this looks this:

    locator: typing.Union[selenium.webdriver.remote.webelement.WebElement,selenium.webdriver.support.event_firing_webdriver.EventFiringWebElement, str], 
    target: typing.Union[selenium.webdriver.remote.webelement.WebElement,selenium.webdriver.support.event_firing_webdriver.EventFiringWebElement, str], 
    html5: bool=False
    

    For me, having the full path to the type declaration is fine but for some this sort of presentation might be "scary" or not very readable. At least when generating html docs, it would be a bit nicer if the paths were to be shown only on tooltips and the "readable" part of the arguments would be like:

    locator: Union[WebElement,EventFiringWebElement, str], 
    target: Union[WebElement,EventFiringWebElement, str], 
    html5: bool=False
    

    and then, when hovering on, say, "WebElement" string, there would be tooltip (for example, with span tag and title) shown with full type information.

  5. pekkaklarck commented on Jun 23, 2020

    @pekkaklarck
    MemberAuthor

    That definitely doesn't look good. I think it would be best if the doc just showed locator: LocatorType instead of resolving LocatorType but I don't know is implementing that possible. It probably would be better to submit a separate issue about this.

  6. pekkaklarck commented on Jun 23, 2020

    @pekkaklarck
    MemberAuthor

    Could you @rasjani test does from __future__ import annotations help? For more details about it and why it could help see https://www.python.org/dev/peps/pep-0563/.

  7. rasjani commented on Jun 25, 2020

    @rasjani
    Contributor

    @pekkaklarck i dont know enough about type annotation internals to make any statements what so ever but if "test" by adding that future import to libdoc is enough, it did not have any effect at least on 3.7.7

  8. xylix commented on Aug 13, 2020

    @xylix
    Contributor

    I think just changing the splitting of arguments makes (at least in our project, but I would expect similar readability in other KWs with a lot of arguments) the arg doc much more readable. See
    Screenshot 2020-08-13 at 11 01 50
    Screenshot 2020-08-13 at 11 01 42

    Was there agreement on what sort of syntax highlighting was desired and does it require libdoc model changes that are incompatible with old format?

  9. Snooz82 commented on Aug 20, 2020

    @Snooz82
    Member

    @xylix Kerkko,

    You changed this already in libdoc, right?
    Could you do a PR, then Maybe @pekkaklarck could put it this min improvement to 3.2.2

  10. pekkaklarck commented on Aug 20, 2020

    @pekkaklarck
    MemberAuthor

    Do I get it right that the enhancement by @xylix just splits arguments to multiple lines? Something like that could be done already in 3.2.2. Could possibly be done conditionally depending on argument count or the length of the whole argument spec. Another alternative would be adding max width to the argument column.

    Actual syntax highlighting requires bigger changes to Libdoc model. Don't think it's safe in 3.2.2.

  11. aaltat commented on Aug 20, 2020

    @aaltat
    Contributor

    Generally speaking I would prefer a constant style with arguments (all formated in the same way, regardless of the number or length), because constant style makes it easier to read. From the users point of view, they may prefer current style or each argument splitted to own line and it might make better to provide a command line argument to choose which style is they prefer.

    Other option could be that if library uses typing hints then all keywords arguments would be splitting to own lines. This makes easier to read the arguments and their types. And if typing hints are not present, arguments would use the current style.

  12. 5 remaining items

  13. pekkaklarck commented on Oct 20, 2020

    @pekkaklarck
    MemberAuthor

    Libdoc getting some kind of built-in help explaining the argument syntax would be great as well. It could get a separate issue or be implemented as part of this one.

  14. mkorpela commented on Oct 28, 2020

    @mkorpela
    Member

    Screenshot 2020-10-28 at 10 16 57

  15. Snooz82 commented on Oct 30, 2020

    @Snooz82
    Member

    Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions