Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pekkaklarck opened this issue May 29, 2020 · 17 comments
Closed

Comments

@pekkaklarck
Copy link
Member

pekkaklarck commented May 29, 2020

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.

@pekkaklarck
Copy link
Member Author

Moved to 3.3 scope because:

@aaltat
Copy link
Contributor

aaltat commented Jun 6, 2020

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.

@rasjani
Copy link
Contributor

rasjani commented Jun 23, 2020

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.

@pekkaklarck
Copy link
Member Author

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.

@pekkaklarck
Copy link
Member Author

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/.

@rasjani
Copy link
Contributor

rasjani commented Jun 25, 2020

@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

@xylix
Copy link
Contributor

xylix commented Aug 13, 2020

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?

@Snooz82
Copy link
Member

Snooz82 commented Aug 20, 2020

@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

@pekkaklarck
Copy link
Member Author

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.

@aaltat
Copy link
Contributor

aaltat commented Aug 20, 2020

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.

@rasjani
Copy link
Contributor

rasjani commented Aug 20, 2020

@aaltat from my pov, showing typing hints is really good. Even in a long run too because that exposes a bit of python land to people and exposing same syntax is good. But there are few angles, first: How the type hints are rendered atm is IMO a bit hard to read (this is my main issue) Second: would the "Python bleed" to documentation be considered bad cuz it would give indication that core prefers python ? I don't remember seeing keyword docs made from java or remote libs having the type information shown even thou in java that most likely is very easy to implement. Which also makes me think that from POV of tester writing test data, having 2 different styles for type hints would be a bit weird ?

@xylix
Copy link
Contributor

xylix commented Aug 21, 2020

#3638 @pekkaklarck Do you have any input on how we should put a part of the HTML template behind a command line flag. Should we do this html base change on python side and only if flag is set?

@pekkaklarck
Copy link
Member Author

pekkaklarck commented Aug 21, 2020

I personally don't think this should be controlled by a command line option. This is why:

  • I'm fairly certain we can come up with good heuristics when to split arguments to multiple rows and when not.
  • Or if splitting arguments to own rows generally works better we can do it always.
  • Which style works better varies between keywords. A single cli option doesn't take that into account.
  • All configuration complicates things. In this case it would make Libdoc usage a bit harder, makes implementing this harder, requires documentation changes, etc.
  • If this is configurable, it's very likely most Libdoc users don't find about this. Automatically formatting arguments better is, well, better.
  • The end user is the person reading Libdoc output and they generally don't have control over the cli option.

Anyway, this topic should get its own issue where it can be discussed further. I notice @xylix already created a PR but we'd anyway need an issue for tracking purposes and discussion in the issue is preserved even if the PR would be closed and new created. Could you @xylix create the issue as well?

@xylix
Copy link
Contributor

xylix commented Aug 24, 2020

Made a tracking issue at #3639

pekkaklarck added a commit that referenced this issue Oct 5, 2020
ArgInfo objects are easy to use for Libdoc when it needs to work with
each argument. Helps implementing #3578 and #3586.
@pekkaklarck
Copy link
Member Author

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.

@mkorpela
Copy link
Member

Screenshot 2020-10-28 at 10 16 57

@Snooz82
Copy link
Member

Snooz82 commented Oct 30, 2020

Done

@Snooz82 Snooz82 closed this as completed Oct 30, 2020
vokiput pushed a commit to vokiput/robotframework that referenced this issue Dec 27, 2020
ArgInfo objects are easy to use for Libdoc when it needs to work with
each argument. Helps implementing robotframework#3578 and robotframework#3586.
pekkaklarck added a commit that referenced this issue Feb 5, 2021
Also rewrite section explaining how arguments are shown in general
because that has been changed by #3586.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants