Skip to content

Commit

Permalink
Add warn about usage of applicable and hasmethod
Browse files Browse the repository at this point in the history
This commit adds a warning about the functions `applicable` and
`hasmethod`. A user reading the current documentation can think that if
those functions return `true`, we can call the method without errors.
However, it is not always the case and should be clearly stated.

Closes JuliaLang#51258
  • Loading branch information
ronisbr committed Sep 10, 2023
1 parent 7b9fdf8 commit 3b9ab69
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,14 @@ Determine whether the given generic function has a method applicable to the give
See also [`hasmethod`](@ref).
!!! warning
It is not guaranteed that the function `f` will provide the expected return
or will not throw exceptions if `applicable` returns `true`. For example,
one function can define a general method like `f(x::Any) = error("Type not
supported")` to catch unsupported types. In this case, `applicable` can
return `true`, but an error will be thrown when calling `f` with the
selected arguments.
# Examples
```jldoctest
julia> function f(x, y)
Expand Down
8 changes: 8 additions & 0 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1902,6 +1902,14 @@ the provided names must be a subset of the method's keyword arguments.
See also [`applicable`](@ref).
!!! warning
It is not guaranteed that the function `f` will provide the expected return
or will not throw exceptions if `hasmethod` returns `true`. For example,
one function can define a general method like `f(x::Any) = error("Type not
supported")` to catch unsupported types. In this case, `hasmethod` can
return `true`, but an error will be thrown when calling `f` with the
selected arguments.
!!! compat "Julia 1.2"
Providing keyword argument names requires Julia 1.2 or later.
Expand Down

0 comments on commit 3b9ab69

Please sign in to comment.