Discover fixes

Backport the fix for discovery in packages from Python bugtracker.
because once python releases a fixed upstream version we'll not want to monkeypatch that.