Get the latest tech news

__init__.py files are optional. Here's why you should still use them


If you’ve ever googled the question “Why do Python packages have empty __init__.py files?”, you could get the idea that Python packages wouldn’t work without them. This is a common misconception—they’ve been optional since Python 3.3! Why then, do most Python projects still have them?

Tools like mypy and ruff also need to understand what is a package and what isn’t, in order to work correctly. If you use namespace packages for this purpose, you’re probably aware of the trade-offs, and you’ve likely already struggled with issues of tooling compatibility and developer confusion. So long as you don’t need the advanced features of implicit namespace packages, you should stick to using__init__.py files.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of init__.py files

init__.py files

Photo of init__.py

init__.py