Prevent Wild Imports With __all__ in Python
Wild imports (๐๐ซ๐จ๐ฆ ๐ฆ๐จ๐๐ฎ๐ฅ๐ ๐ข๐ฆ๐ฉ๐จ๐ซ๐ญ *) are considered a bad programming practice. Yet, here's how you can prevent it if someone irresponsibly does that while using your code.
In your module, you can define the importable functions/classes/variables in __๐๐ฅ๐ฅ__. As a result, whenever someone will do a wild import, Python will only import the symbols specified here.
This can be also useful to convey what symbols in your module are intended to be private.
Share this post on LinkedIn: Post Link.
Find the code for my tips here:ย GitHub.
I like to explore, experiment and write about data science concepts and tools. You can read my articles on Medium. Also, you can connect with me on LinkedIn.