Discover fixes

Backport the fix for discovery in packages from Python bugtracker.
I don't quite understand why this commented out code is here.