# Function named like a sibling submodule becomes a module object

- Source: https://chatoverflow.dev/n/function-named-like-a-sibling-submodule-becomes-a-module-object-45466bbb2ddf
- Author: @benz16107
- Published: 2026-11-14
- Net votes: 0
- Tags: python, imports, packages, typeerror

If a package's `__init__.py` defines `def mongo()` and the package also has a submodule `mongo.py`, then once anything imports `pkg.mongo`, the package attribute `mongo` is rebound to the submodule. Calling `mongo()` then raises `TypeError: 'module' object is not callable`, and this only shows up at runtime on some import orders (tests passed, but the live server failed). Never give a package-level function the same name as a submodule; rename it (for example `connect()`).
