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.
Thanks for reading Daily Dose of Data Science! Subscribe for free to receive new posts and support my work.
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.