Skip to content

Commit

Permalink
Filter out more doc signature expressions (#774)
Browse files Browse the repository at this point in the history
* Filter out more doc signature expressions

Revise extracts the documented expression and puts that before the full
doc expression in the revision queue. E.g. in `"docs" f(x) = x` there
will be a revision of `f(x) = x` followed by a revision of the full
expresion (`"docs" f(x) = x`). However, in many cases a docstring is
only attached to a signature (not a function body/struct definition,
etc.) and in this case the revision of the signature is not needed.

Revise already filters out the base case, `"docs" f(x)`. This patch
extends this filtering to also apply to `where`-clauses such as e.g.
`"docs" f(x::T) where T <: Integer`.

Concretely, this patch fixes #735, i.e. revising doc expressions where
the signature doesn't lower without the context of the doc macro. As a
bonus, slightly less work has to be done for e.g. `"docs" f(x::T) where
T` since this is also filtered out.

* Set version to 3.5.8.
  • Loading branch information
fredrikekre authored Nov 10, 2023
1 parent 6f71e52 commit 1059181
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Revise"
uuid = "295af30f-e4ad-537b-8983-00126c2a3abe"
version = "3.5.7"
version = "3.5.8"

[deps]
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
Expand Down
11 changes: 10 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,20 @@ istrivial(a) = a === nothing || isa(a, LineNumberNode)

isgoto(stmt) = isa(stmt, Core.GotoNode) | isexpr(stmt, :gotoifnot)

function unwrap_where(ex::Expr)
while isexpr(ex, :where)
ex = ex.args[1]
end
return ex
end

function pushex!(exsigs::ExprsSigs, ex::Expr)
uex = unwrap(ex)
if is_doc_expr(uex)
body = uex.args[4]
if isa(body, Expr) && body.head !== :call # don't trigger for docexprs like `"docstr" f(x::Int)`
# Don't trigger for exprs where the documented expression is just a signature
# (e.g. `"docstr" f(x::Int)`, `"docstr" f(x::T) where T` etc.)
if isa(body, Expr) && unwrap_where(body).head !== :call
exsigs[RelocatableExpr(body)] = nothing
end
if length(uex.args) < 5
Expand Down
17 changes: 17 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,23 @@ const issue639report = []
pop!(LOAD_PATH)
end

do_test("doc expr signature") && @testset "Docstring attached to signatures" begin
md = Revise.ModuleExprsSigs(Main)
Revise.parse_source!(md, """
module DocstringSigsOnly
function f end
"basecase" f(x)
"basecase with type" f(x::Int)
"basecase no varname" f(::Float64)
"where" f(x::T) where T <: Int8
"where no varname" f(::T) where T <: String
end
""", "test2", Main)
# Simply test that the "bodies" of the doc exprs are not included as
# standalone expressions.
@test length(md[Main.DocstringSigsOnly]) == 6 # 1 func + 5 doc exprs
end

do_test("Undef in docstrings") && @testset "Undef in docstrings" begin
fn = Base.find_source_file("abstractset.jl") # has lots of examples of """str""" func1, func2
mexsold = Revise.parse_source(fn, Base)
Expand Down

2 comments on commit 1059181

@KristofferC
Copy link
Collaborator

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/95096

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.5.8 -m "<description of version>" 1059181bed06387e9fbcea137dce28a80c5c45d9
git push origin v3.5.8

Please sign in to comment.