For example, the module securehash is std/sha1 now, but if I didn't want a deprecated warning and I didn't want to import std/sha1 for versions of Nim where it doesn't exist can I know whether or not std/sha1 exists? Something like:

when isModule(std/sha1):
  import std/sha1
else:
  import securehash

I think none of these work:

when declared(std/sha1): ...
when declared(std/sha1.SecureHash): ...
when declared(std.sha1.SecureHash): ...
when declared(std.sha1): ...
when (compiles do: import std/sha1): ...

2018-04-14 11:29:01
when (compiles do: import std/sha1): ... this one works
2018-04-14 14:05:48

Are you sure?

# moduletest.nim
import std/sha1

when (compiles do: import std/sha1):
  static: echo "works"
  import std/sha1
else:
  static: echo "doesn't work"
  import securehash

> nim c moduletest
Hint: used config file 'C:\nim-0.18.0\config\nim.cfg' [Conf]
Hint: system [Processing]
Hint: moduletest [Processing]
Hint: sha1 [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: math [Processing]
Hint: algorithm [Processing]
doesn't work
Hint: securehash [Processing]
moduletest.nim(8, 10) Warning: securehash is deprecated [Deprecated]

2018-04-14 14:45:34
ok, it doesnt work on stable, but works on devel 2018-04-14 14:49:41
Since 0.18 doesn't support it yet, you need a version check like: when NimMajor < 1 and NimMinor < 18
2018-04-14 15:29:45