Skip to content
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

Move template expansion to "format-time" #96

Merged
merged 2 commits into from
Aug 12, 2020

Conversation

MichaelHatherly
Copy link
Member

This moves the expansion of templates from macro expansion time to later on. This allows us to avoid having to search through expressions looking for the actual expression type since those may be hidden by "decorator" macros. It also handles cases where @doc is used on a string macro docstring, such as

@doc raw"..." f(x) = x

Implementation is based on a new internal abbreviation type called Template which gets prepended and appended to docstrings in modules where templates are available. Then, during formatting, we expand these Template abbreviations into there definitions.

Fixes #73.

This moves the expansion of templates from macro expansion time to later
on. This allows us to avoid having to search through expressions looking
for the actual expression type since those may be hidden by "decorator"
macros. It also handles cases where `@doc` is used on a string macro
docstring, such as

    @doc raw"..." f(x) = x

Implementation is based on a new internal abbreviation type called
`Template` which gets prepended and appended to docstrings in modules
where templates are available. Then, during formatting, we expand these
`Template` abbreviations into there definitions.

Fixes JuliaDocs#73.
@MichaelHatherly
Copy link
Member Author

@bzinberg, this should resolve those issues in #73, if you're able to try this branch out that would be great, thanks.

@MichaelHatherly
Copy link
Member Author

Failures on 1.6 due to #93. Unrelated to this change.

Changes tuple comparision from a roundabout string comparision to use
proper subtype comparision.

Also adjusts test cases to avoid triggering type alias printing such as
`Array{T,1}` to `Vector{T}` which fails on Julia 1.6.
@MichaelHatherly
Copy link
Member Author

Commit added for fixes for #93.

Changes tuple comparison from a roundabout string comparison to use proper subtype comparison.

Also adjusts test cases to avoid triggering type alias printing such as Array{T,1} to Vector{T} which fails on Julia 1.6.

Copy link
Member

@mortenpi mortenpi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment there are no tests for #73, right?

Comment on lines -319 to -326
:typesig => Union{Tuple{Union{T, Nothing}}, Tuple{Union{T, Nothing}, T}, Tuple{T}} where T <: Number,
:typesig => Union{Tuple{Union{T, Nothing}}, Tuple{Union{T, Nothing}, T}, Tuple{T}} where T <: Integer,
:module => M,
)
DSE.format(DSE.TYPEDSIGNATURES, buf, doc)
str = String(take!(buf))
@test occursin("\n```julia\n", str)
@test occursin("\nk_7(x::Union{Nothing, T<:Number}) -> Union{Nothing, Number}\n", str)
@test occursin("\nk_7(x::Union{Nothing, T<:Number}, y::T<:Number) -> Union{Nothing, T<:Number}\n", str)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the Vector/Matrix changes, but is there a similar printing change with Number prompting the Number -> Integer change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly. It may also be due to use of return_type to determine types after -> which means all bets are off for cross-version compat here.

@MichaelHatherly
Copy link
Member Author

At the moment there are no tests for #73, right?

Base.@kwdef uses @__doc__ so this should cover that issue.

@MichaelHatherly MichaelHatherly merged commit 339cd6d into JuliaDocs:master Aug 12, 2020
@MichaelHatherly MichaelHatherly deleted the mh/fix-templates branch August 12, 2020 20:58
@bzinberg
Copy link

@bzinberg, this should resolve those issues in #73, if you're able to try this branch out that would be great, thanks.

Hey, sorry I didn't get to this in time. Aiming to try it by the weekend.

@MichaelHatherly
Copy link
Member Author

No worries @bzinberg 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@template broken with Base.@__doc__?
3 participants