Comments (6)
It's probably due to the assumption that typesig
will always have a field called :a
:
DocStringExtensions.jl/src/abbreviations.jl
Lines 382 to 391 in 9075207
I won't have time to dig into this deeper though, but would happily take a PR.
from docstringextensions.jl.
@mortenpi I'm looking into this and will be happy to submit a PR.
I do have a question though. I have the following file:
cat test.jl
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ File: test.jl
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ using DocStringExtensions
2 │
3 │ """
4 │ $TYPEDSIGNATURES
5 │
6 │ hello_world is a function
7 │ """
8 │ function hello_world(::Type{T}, s::AbstractString) where {T <: Number}
9 │ @show T, s
10 │ nothing
11 │ end
12 │
13 │ println(@doc hello_world(Number, "hi"))
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
And I have this minimal example, and when I run it in DocStringExtensions, I get the following
binding = hello_world
typesig = Union{Tuple{T}, Tuple{Type{T},AbstractString}} where T<:Number
modname = Main
func = hello_world
```julia
hello_world(?::T<:Number, s::T<:Number)
```
hello_world is a function
I put @show
calls in the following function for the above output:
DocStringExtensions.jl/src/abbreviations.jl
Lines 367 to 371 in 9075207
Why does the typesig
have Tuple{Type{T},AbstractString}
? Shouldn't it just be AbstractString
? Is this a bug? Is DocStringExtensions generating typesig
or is that happening in base julia?
If I don't use a generic typeof as the first argument, this works as expected.
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ File: test.jl
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ using DocStringExtensions
2 │
3 │ """
4 │ $TYPEDSIGNATURES
5 │
6 │ hello_world is a function
7 │ """
8 │ function hello_world(::Type{Number}, s::AbstractString)
9 │ @show Number, s
10 │ nothing
11 │ end
12 │
13 │ println(@doc hello_world(Number, "hi"))
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
binding = hello_world
typesig = Tuple{Type{Number},AbstractString}
modname = Main
func = hello_world
```julia
hello_world(?::Type{Number}, s::AbstractString)
```
hello_world is a function
from docstringextensions.jl.
I think I figured out the answer to part of my question
struct __CUSTOM__ end
function Docs.formatdoc(buffer, docstr, ::Type{__CUSTOM__})
@show docstr.data[:typesig]
end
"""
hello_world is a function
$__CUSTOM__
"""
function hello_world(::Type{T}, s::AbstractString) where T <: Number
@show Number, s
nothing
end
println(@doc hello_world(Number, "hi"))
This returns
docstr.data[:typesig] = Union{Tuple{T}, Tuple{Type{T},AbstractString}} where T<:Number
hello_world is a function
So this is generated by Julia. I'm still not sure if Tuple{Type{T},AbstractString}
is a bug or not.
from docstringextensions.jl.
Okay, it's seems that it is not a bug, but intended. Sorry for spamming this thread. I'm still trying to figure out why the typesig
is the way it is, and I have more questions than answers.
from docstringextensions.jl.
Thanks for tackling this @kdheepak!
To answer your question about the type signature: yep, it's something that comes from Julia itself. It's created by the Base.Docs.signature
function:
julia> Base.Docs.signature(:(function foo end))
:(Union{})
julia> Base.Docs.signature(:(function foo(::Int) end))
:(Union{Tuple{Int}})
julia> Base.Docs.signature(:(function foo(::Vector{T}) where T <: Number end))
:(Union{Tuple{Vector{T}}, Tuple{T}} where T <: Number)
The weirdness about the parametric signature, I believe, is a bug in Docs.signature
(JuliaLang/julia#29437). The second Tuple{T}
shouldn't be there, which you can see if you look up the signature for the method in the method table:
julia> function foo(::Int) end
foo (generic function with 1 method)
julia> function foo(::Vector{T}) where T <: Number end
foo (generic function with 2 methods)
julia> methods(foo)
# 2 methods for generic function "foo":
[1] foo(::Int64) in Main at REPL[4]:1
[2] foo(::Array{T,1}) where T<:Number in Main at REPL[10]:1
julia> methods(foo).ms[1].sig
Tuple{typeof(foo),Int64}
julia> methods(foo).ms[2].sig
Tuple{typeof(foo),Array{T,1}} where T<:Number
So, coming back to the original example, the typesig
for function hello_world(::Type{Number}, s::AbstractString) end
should be the following UnionAll
: Tuple{Type{T},AbstractString} where T<:Number
. However, that's not what the docsystem stores, so in DocStringExtensions we'd need some sort of a workaround for that bug.
from docstringextensions.jl.
Thanks for the comment! This is exactly what I wanted to know. 1) it is a bug with the signature function, and 2) how to generate the signature with the Base.Docs
module and what the Julia type system thinks the signature is. I'll post more information in the PR.
from docstringextensions.jl.
Related Issues (20)
- How to use alias of AbstractArray instead of the full name? (Feature request) HOT 2
- Display parametric types in a better way? HOT 2
- Remove documentation page for v0.1
- Update CI badges in the README HOT 2
- TagBot trigger issue HOT 7
- The `TYPES` template does not apply to parametric types
- MODULES key not found for `@template` HOT 1
- Doctest failures
- Format docstrings HOT 4
- Considering writing a script to add function signatures to a code base. HOT 5
- Examples of how to use all of the functionality HOT 5
- expected test failure from the incoming `Core.Compiler` changes HOT 3
- Cannot get source for generated functions
- feature request: non-api doc marker HOT 7
- How to show default values and types of keyword arguments? HOT 1
- Update docs to latest version of Documenter HOT 5
- different abbreviations for concrete and abstract types HOT 1
- FUNCTIONNAME inside a function that generates the docstring HOT 7
- Would it be possible to add a TYPEDMETHODLIST abbreviation HOT 2
- Internal errors when (ab)using `@template` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docstringextensions.jl.