# Determine whether any one-argument method exists

**URL:** <https://discourse.julialang.org/t/determine-whether-any-one-argument-method-exists/19917>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 22, 2019, 8:34am UTC](https://discourse.julialang.org/t/determine-whether-any-one-argument-method-exists/19917 "2019-01-22T08:34:03Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 22, 2019, 1:23pm UTC](https://discourse.julialang.org/t/determine-whether-any-one-argument-method-exists/19917/2 "2019-01-22T13:23:51Z")

</div>

> [@ettersi](#):
>
> This seems like a bug in the language (albeit arguable not the most severe one). Is there a workaround for this?

It’s not a bug. ~~`hasmethod(f, Tuple{Union{}})` or~~ `hasmethod(f, Tuple{Any})` are asking whether `f` has a method whose argument type is `Any` or any _supertype_ of `Any`, not any _subtype_ which is what you are hoping for.

For example, `hasmethod(f, Tuple{Real})` _will_ succeed if there is an `f(x::Real)` method, but also if there is an `f(x::Number)` or `f(x::Any)` method. It _won’t_ succeed if there is only an `f(x::Int)` method.

One thing you could do to check whether `f` has a single-argument method would be to check `any(m -> m.nargs == 2, methods(f))`, although this relies on the undocumented internal field `nargs` of the `Method` type. (`m.nargs == 2` seems to be correct for to test for 1 argument, since the function itself is apparently counted as an “argument” here.)

_Update:_ My bad, I was confusing `Union{}` with `Any`. As was pointed out below, `Union{}` is a _supertype_ of every type, so it seems like it should work.

---

_[View the full topic](https://discourse.julialang.org/t/determine-whether-any-one-argument-method-exists/19917)._
