judy2k / stupid-python-tricks

Stupid Python tricks.
The Unlicense
144 stars 27 forks source link

better-ish API - no need to write 'from ish import ish' #2

Closed kmike closed 9 years ago

kmike commented 9 years ago

Hi,

Me and @eliasdorneles realized that ish API could be better. We're using it heavily in production, and from ish import ish is too verbose and tiresome to type. We wanted to be able to do just import ish, which provides a cleaner and DRYer API. The implementation is in this PR.

What do you think about it? There are tests and changes are fully backwards compatible.

judy2k commented 9 years ago

I love you - I had planned to do exactly this thing!

snoack commented 9 years ago

I were about to add that feature as well. However, I wouldn't even bother to subclass the module type. Note that you can put any kind of objects in sys.modules. So following code would already be sufficient:

ish._module = sys.modules[__name__]
sys.modules[__name__] = ish