boltons icon indicating copy to clipboard operation
boltons copied to clipboard

Fix implicit relative imports

Open skravik opened this issue 4 years ago • 2 comments

Triggers caught ImportError fallbacks when run on Python 3, which can lead to subtle unexpected behavior. Some files already had the correct syntax, this PR updates the remainder.

skravik avatar Mar 16 '22 22:03 skravik

Part of the way boltons is structured is to make it easy to partially vendor it. For instance, using debugutils.py should be as simple as dropping debugutils.py and typeutils.py into any folder. The absolute import would break this (though only trivially). Maybe they should be:

from .typeutils import make_sentinal

Instead?

bwatson-dk avatar Mar 29 '22 17:03 bwatson-dk

Good points, ease of vendoring may be a reason to keep the (explicit) relative imports. The PR was just aiming to maintain consistency with the few existing places in the code base that were already using an absolute style. Could certainly update those too though:

https://github.com/mahmoud/boltons/blob/395f690f4a24331c4554e2169ac18a15955a4eab/boltons/cacheutils.py#L85 https://github.com/mahmoud/boltons/blob/395f690f4a24331c4554e2169ac18a15955a4eab/boltons/funcutils.py#L67 https://github.com/mahmoud/boltons/blob/395f690f4a24331c4554e2169ac18a15955a4eab/boltons/urlutils.py#L1541

I don't have a strong preference, so whichever the author prefers. I'm happy to update PR as needed.

skravik avatar Mar 30 '22 00:03 skravik

Hey! Thanks for this (and the patience in awaiting reply). As I'm sure you've gathered, these sentinels are best effort, and mostly for repr/docs generation niceness (hence the ImportError catching for folks who vendor).

But, we don't want to fill logs with warnings if we don't have to. I think I do prefer the explicit relative imports, assuming it passes all tests. Could you rebase and make that change? Thanks!

mahmoud avatar Dec 08 '22 09:12 mahmoud

Rebased and updated. Thanks!

skravik avatar Dec 10 '22 08:12 skravik

LGTM, thanks again!

mahmoud avatar Dec 10 '22 10:12 mahmoud