This is a super opinionated project! The gist is this — what if we cleaned up every unneccessary name from a Python module once it’s fully loaded? By using the pattern below, all of your namespaces will be kept clean and tidy.
"""Pretend this is the contents of module.py!"""__export__ = {"MyType","myfunc",}class MyType: ...def myfunc(x): ...if__name__=="__main__": ...else:for _ in (*locals(), "_"):ifnot _.startswith("__") and _ notin __export__:dellocals()[_]
I put the above pattern in a package called module-hygiene! With this new package, you could rewrite module.py as follows.
"""Pretend this is the contents of module.py!"""__export__ = {"MyType","myfunc",}class MyType: ...def myfunc(x): ...if__name__=="__main__": ...else:from hygiene import cleanupexec(cleanup())
rich-admonitions
The rich Python package is excellent! I’ve added Julia-style in-terminal Markdown admonitions via the rich-admonitions package! Check out some simple usage below.
from rich importprintfrom admonitions import Admonitionmessage = Admonition.note( Admonition.info( Admonition.warning( Admonition.danger( Admonition("We're in too deep! 🥽", header ="Oh jeez...", style ="purple" ) ) ) ))print(message)
│Note│││Info│││││Warning│││││││Danger│││││││││Oh jeez...││││││││││ We're in too deep! 🥽
││││││││││