The task for this is: T85796
I've added the ability to get a selection list for both edit mode bones and pose mode bones.
To do this I had rework the selection logic for this a bit.
Before it only stored the names of objects. This might work will of objects, however as stated it might fail for linked objects (so multiple object can have the same name in some corner cases).
For bones this naming lookup is not good enough as you can select while having multiple armatures active (with the same bone names).
So I had to store the bone pointers instead.
However I guess the previous way of looking up things was because these pointers might be invalidated.
(I'm guessing it can break if you playback or skip frames while selecting)
So I'm not sure that my way is safe or if we need to introduce some safe guards so we can be sure that the pointers are still valid.
In addition to this, I'm quite sure @sybren will not be happen with me just copy pasting old code and calling it a day as they might need some cleanup.