Discover fixes

Backport the fix for discovery in packages from Python bugtracker.
Please add a URL for the issue in the comments.