Nested discovery fixes

Sorry for the lack of tests.  Hopefully I'll get to this tomorrow.
hm maybe it's not worth the hassle, the docstring for `TypeVar` says it's not user facing