-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
abbreviated syntax for docstrings #8965
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
Comments
Is the @doc """
... flowing rivers of technical poetry ...
"""
function foo() ... |
@brk00, we're hoping to drop the |
+1 |
Is this feature expected to arrive for 0.4? |
I made a comment over here that is very relevant to this issue. The situation can be summarized as:
Therefore Markdown parsing must happen when docstring data is rendered as Markdown, rather than when docstrings are parsed as part of Julia's syntax. Until this issue is resolved – i.e. until Markdown parsing is deferred to when the docstring data is used, rather than happening eagerly when the docstring is parsed – docstrings are going to remain "stuck in limbo as a clever macro hack rather than a first class language feature". |
@one-more-minute, @MichaelHatherly, can we come up with a plan for this to happen? What do you see as the necessary steps to having docstrings in the language (without a dependency between parsing Julia code and Markdown parsing). |
@StefanKarpinski, Docile's already extracting bare docstrings from base. In my mind the syntax doesn't really need to be part of the language, since I've managed pretty well so far. (That's not to say having it builtin in some way might be better of course.) The parsing of docstrings is also completely lazy and left until the need to render the raw text, which can be markdown or any other format that someone writes a package for. I believe the package is already covering most of you're suggestions as is, but could always do with more eyes and testers. |
Maybe I'm misunderstanding this, because parsing isn't exactly my area of expertise, but it seems like this should be a pretty trivial change. It's just a case of having the parser take "foo"
bar and create the AST equivalent of @doc doc"foo" ->
bar and it should just work. If someone like @JeffBezanson or @jakebolewski can give me a rough idea of where the code for that should go I'll happily do it myself. |
Is it necessary to do that transformation? Traversing the parsed |
@StefanKarpinski When do you see the Markdown parsing occurring? |
@MichaelHatherly I think it makes more sense to load doc strings dynamically as code is loaded, as opposed to re-parsing and traversing the code at a later point as Docile does. For one thing, the dynamic approach generalises immediately to user code – if loading docs is a separate step we either have to hack |
Yes, that was I concern, but typically I've found that to be relatively fast:
there's probably room for improvement in that as well, since I've not put much time into that yet.
Is this code at the REPL, a script someone might write, or a package? Do we need to be able to document the first two?
Apart from needing |
Sure, both. e.g. if you evaluate a file/form in Juno, or write Also, how do you assign docstrings to the right method of a function statically? I'm sure there are decent ways of doing it but my main concern is that stuff like that just wouldn't be as reliable. |
@MichaelHatherly The 2 entries it found were my recently merged UTF checking module? |
@one-more-minute:
Correct, my reasoning has been that the rendered docstrings are for users of packages. When writing a package I've not seen much need for evaluating a docstring and seeing it rendered right then – it's markdown and so quite readable as is, but that could just be me.
By file/line position and
Not really, if you add it to your
Just traversing over each file in a module and looking for strings in the right places, then taking the current module into account find the object related to that docstring. Is that what you were wanting to know?
I think it's more important to have a consistent place for docstrings to go. Since we have some declarations that don't have an "inside", ( |
About assigning the docstrings, don't you think it would be better if all that was handled directly when parsing the program? (this is thinking of the future, of course, not right away). I.e. just deciding that the string is a doc string, and saving it, along with the metadata, not doing all the Markdown processing. |
I've got zero experience with the parser, so it might very well be better done there :)
Yes it is a gotcha for those coming from some languages, but there are other languages the also put their docstrings above, elixir and rust come to mind. We can't really please everybody I think. If you'd like to give it a try adding them to Docile you're most welcome to. |
No, no, I'm not really a Python person myself, just wanted to raise the issue, and you've answered it just fine, wrt declarations that don't have an inside. |
How are the Since we are already starting to use docstrings with markdown syntax (even if it's not parsed currently) in Base: Does this mean I have green light to make PRs to add these? |
@ScottPJones you weren't actually the first to use bare docstrings it seems :)
@Ismael-VC #11828 might be of interest to you since that moves all the docs over to the new system. |
By the way the example "
# ....
" Instead of: """
# ...
""" I think some_func{with<:a, lot<:of, lot<:of, lot<:of, lot<:of, params}(with, a, lot, lot, lot, lot, of, args...) =
# some code
for # something
# for code
end # this is endfor not func! Instead I would like to change those to: function some_func{with<:a, lot<:of, lot<:of, lot<:of, lot<:of, params}(with, a, lot, lot, lot, lot, of, args...)
# some code
for # something
# for code
end
end And things like that, which seems to be better, I know it's nice to be able to do the former (in the REPL this is helpful), but the latter is better for consistency IMHO. What do you think? |
That's because """ is not available that early in the build process... you are looking at something in Base, not user code. See #11815 for a hopefully merged soon solution. |
@MichaelHatherly I had no choice! 😀 |
And I was the first to use them with Markdown syntax in Base! ;-) |
Lazy.jl was my first package and uses markdown docstrings – I've been planning this stuff for a long time ;) |
I saw a lot of good markdown docstrings in packages, it just surprised me that there was pretty much nothing in Base. I'm a big fan of internal documentation (since most all of my programming is deep in the internals) |
Style-wise: triplequoted for multiline docstrings and single quotes for short one-liners seem the most readable to me. That's what packages have been doing with bare docstrings that I've come across. If I'm reading #11815 correctly that would allow |
I think that we should shoot for a consistent, simple user experience, which seems to be that regardless of how you load code – whether from packages, include, or entered at the REPL – docstrings should work and be available via help immediately. It seems to me that the only way to make that work is for the parser to know about docstrings and stash their content somewhere that is immediately available upon parsing code. At the same time, the constraint that parsing Julia code should not depend on parsing Markdown (or any other document syntax) implies that the docstring data be stashed as plain, unparsed data. In non-interactive mode, the parser could just ignore docstrings. If the user asks for help and has a Markdown package – and it can be a standard module that ships with Julia but is not in Base – then it can be loaded automatically and used to render the docstring data nicely. Since Markdown is pretty readable without Markdown rendering, we could still display any docstrings as-is, even if the Markdown module is absent for some reason. That could very well be the case, for example, on a server where Julia has been installed with a minimal distribution, lacking bells and whistles. With this arrangement, even on such a system, you would get a usable, albeit less fancy REPL help experience. |
Both Base and pre-compiled modules will need some way of providing help info as well. I'm not sure if we want to make this some kind of data segment in a shared object file (i.e. |
Yep, precisely what I'd been trying to say, but said much more precisely and more completely. 👍 (to the 1st comment, also agree to the second comment) |
If people agree with this view of how things should work then we just need to figure out how to get there. |
+1 to finally concluding the docstring saga. Anything more fancy can live in packages. |
Long live docstrings! 👍 |
Wouldn't then all docstrings have to be static? Lifting the parsing of docstrings into the parser is fine, but how do we add documentation for methods generated at a later stage (during macroexpansion for instance)? for meth in (:foo, :bar, :baz)
@eval begin
doc"""
$($meth) is a method
"""
$(meth)() = "hello $($meth)"
end
end |
I guess the association could happen at eval time rather than parse time. |
Good point, definitely would want to be able to handle that. |
Closed by #11836 |
Hooray! |
Rather than
@doc docstring -> foo(x) = ...
, we have discussed allowingdocstring foo(x) = ...
in #8791. i.e. treat any literal string (including string macros!) immediately preceding a function declaration (either one-line orfunction foo...
) as shorthand for@doc
.The text was updated successfully, but these errors were encountered: