sisl icon indicating copy to clipboard operation
sisl copied to clipboard

Documentation: signatures with typehints.

Open pfebrer opened this issue 1 year ago • 9 comments

Function signatures with typehints in the documentation can become very hard to read:

Screenshot from 2023-11-01 17-50-32

I been playing with some CSS, and it is possible to have each parameter in a new line, just as you would do in the source code:

Screenshot from 2023-11-01 18-11-13

Do you think it would be better?

pfebrer avatar Nov 01 '23 17:11 pfebrer

You can tune it further to make it even clearer by adding colors for example:

Screenshot from 2023-11-01 18-20-48

pfebrer avatar Nov 01 '23 17:11 pfebrer

Or even with the weight of the font, here I avoid setting the typehint to bold:

Screenshot from 2023-11-01 18-23-45

So, really you can do anything you come up with.

The way I did it applies the styling to methods as well, but I'm sure there's some way to avoid it:

Screenshot from 2023-11-01 18-23-38

pfebrer avatar Nov 01 '23 17:11 pfebrer

Perhaps we can do a poll on discord to see which layout users prefer :)

pfebrer avatar Nov 01 '23 17:11 pfebrer

I really like the grayed out typing construct. I agree the typing is horrendous, I thought it would help clarify how the arguments are allowed, but it is just too much, see here: https://zerothi.github.io/sisl/api/generated/sisl.Geometry.html#sisl.Geometry.auc2sc I really would like it to just point to AtomsLike.

zerothi avatar Nov 01 '23 19:11 zerothi

I really would like it to just point to AtomsLike.

See the trick here: https://github.com/pandas-dev/pandas/issues/33025#issuecomment-699636759

I think it would be very useful for AtomsLike and AtomsArgument.

I really like the grayed out typing construct.

This one: ?

image

pfebrer avatar Nov 01 '23 21:11 pfebrer

Great reference for hiding the information, lets do something like that. I'll play later.

As for the type hinting, I kind of prefer how it is shown in Geometry, no type-hints at the interface (for clarity), and an extensive type declaration in the Parameters section. I am not fully sure why your PdosPlot shows differently from Geometry...

zerothi avatar Nov 02 '23 08:11 zerothi

Don't you think the typehinted signature is clear enough if you give one line to each parameter? I like it because it gives you a quick idea of what the argument expects, as in the source code.

I think this:

Screenshot from 2023-11-01 18-23-45

Is more helpful than this:

Screenshot from 2023-11-02 09-58-41

(I know the typing is missing in the argument description)

pfebrer avatar Nov 02 '23 09:11 pfebrer

The typing should be present in the argument description, I don't mind having them in the interface, IFF they are simple lines, the Geometry example is really bad since there the typing gets excessively long. If it hinders readability, I don't want it ;) Users don't really care, and if it becomes difficult to see the order of arguments, it becomes hard. So in that case the 1-line per argument is great!

zerothi avatar Nov 02 '23 09:11 zerothi

Yeah I agree, I would like that the typehints are shown in the signature with 1 line per argument only if it is possible to use the trick to avoid expanding the complex typehints.

I think for users that are already familiar with type hints that might help, and also it shows that the package is type hinted, which is not clear if the typehint appears only in the description.

pfebrer avatar Nov 02 '23 09:11 pfebrer