Giter VIP home page Giter VIP logo

Comments (9)

MichaelHatherly avatar MichaelHatherly commented on July 22, 2024 1

It's possible to retrieve default argument values, it's just probably going to require digging into the output of code_lowered since the documented Expr itself is never saved. You'd want to start by looking at how the current TYPEDSIGNATURES does it's thing and then use a code_lowered to access the IR and extract values from there. This is unlikely to be a particularly easy thing to do robustly.

from docstringextensions.jl.

JanWeidnerPTW avatar JanWeidnerPTW commented on July 22, 2024 1

since the documented Expr itself is never saved.

Is there some technical obstacle with saving the documented expression? The expression seems to be very valuable information.

from docstringextensions.jl.

JanWeidnerPTW avatar JanWeidnerPTW commented on July 22, 2024 1

Awesome! BTW let me take this opportunity to thank you for all the great work you did on the julia documentation system @MichaelHatherly

from docstringextensions.jl.

MichaelHatherly avatar MichaelHatherly commented on July 22, 2024

I recall trying to add this a long time ago, works well for the small cases such as numbers and the like, but as soon as you have a default value being some kind of complex nested object the info becomes more of a hindrance than a help. Would need some kind of display limiting if we tried this again.

from docstringextensions.jl.

ShuhuaGao avatar ShuhuaGao commented on July 22, 2024

Would need some kind of display limiting if we tried this again.

It makes sense since most default values tend to be constants of some primitive types, e.g., numbers and string. For other more complicated cases, a placeholder may be used, like #i for the i-th default value. The author is required to document these placeholders manually.

f(a::Int64, b::ComplexType=#1, c::ComplexType=#2)

The same issue exists in keyword arguments. Consider the following function

"""
$(TYPEDSIGNATURES)
"""
function f_default(a::Int=1, b::Int=2; c::String="Hello", d::Float64=3.14)
end

which generates
Snipaste_2021-02-05_16-42-02
Also, it is not obvious to see from the above signatures whether the signature f_default(a::Int64; c) is legal. Of course, listing all possible methods may encounter the combinational explosion problem. Thus, showing default values of selected types or a placeholder otherwise may be a solution.

from docstringextensions.jl.

andyDoucette avatar andyDoucette commented on July 22, 2024

+1 on this. Having the defaults in the signatures is very important. I think 98% of the time, the defaults are simple things like integers, short strings, bools, etc. Converting the default to a string and having a maximum length with a "..." at the end if it exceeds that should cover the vast majority of the cases, I'd think. I'd do it myself but I have no idea how to even get the default. :) Cudos to making this package.

from docstringextensions.jl.

MichaelHatherly avatar MichaelHatherly commented on July 22, 2024

#133 is intended to add support for this kind of thing. I just need some spare time to actually finish it off though.

from docstringextensions.jl.

MichaelHatherly avatar MichaelHatherly commented on July 22, 2024

Thanks @JanWeidnerPTW!

from docstringextensions.jl.

MichaelHatherly avatar MichaelHatherly commented on July 22, 2024

I'll probably merge #133 sometime thing week, after which it's just a matter of using the feature to implement a fix for this one.

from docstringextensions.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.