What's the correct way to including functions that only got introduce from a certain version of Julia?

I want to support all LTS Julia versions which is currently 1.0.5. However, some functions like nonmissingtype is only introduced in 1.3

What’s the correct way to support these type of functions? Should I just check for Julia version in PacakgeName.jl and then if they are not there then with something like this?

if VERSION < v"1.3.0"
  using Missings: nonmissingtype
end
3 Likes

Yes, this is a common approach. But presumably you want some fallback for versions before if the code actually uses nonmissingtype.

I think the cleanest approach is to just require the Julia version you need in the [compat] section, and drop support for versions before.

I want to support any LTS Julia version, so unless LTS becomes like 1.4, I will continue to support it.

3 Likes

I think the “best” solution is to add it to Compat and write using Compat: nonmissingtype; i.e., let Compat implement the branch. This way, other people can also use Compat for this.

Though if VERSION < v"1.3.0" looks like a good solution too.

3 Likes