mirror of
https://github.com/VectifyAI/PageIndex.git
synced 2026-07-24 21:41:04 +02:00
27 lines
1.4 KiB
Python
27 lines
1.4 KiB
Python
# pageindex/page_index.py — re-exports from index/page_index.py
|
|
import sys
|
|
import types
|
|
from .index.page_index import * # noqa: F401,F403,E402
|
|
|
|
# pageindex/__init__.py binds the FUNCTION `page_index` as the package
|
|
# attribute `pageindex.page_index` (`from .index.page_index import *`). But
|
|
# this file is ALSO a real submodule of the same name — the moment anything,
|
|
# anywhere in the process, does `import pageindex.page_index` (exactly what
|
|
# `from pageindex.page_index import X` triggers), Python's import machinery
|
|
# overwrites that package attribute with THIS module object, clobbering the
|
|
# function binding. Afterwards `from pageindex import page_index; page_index(x)`
|
|
# would raise "TypeError: 'module' object is not callable" — silently, and
|
|
# depending entirely on whether this submodule happened to be imported yet.
|
|
#
|
|
# Fix: make this module itself callable, delegating to the real function, so
|
|
# whichever object ends up sitting in the `pageindex.page_index` slot — the
|
|
# function or this module — is callable either way. Both `from pageindex.page_index
|
|
# import page_index_main` (module attribute access) and
|
|
# `from pageindex import page_index; page_index(x)` (call) keep working
|
|
# regardless of import order.
|
|
class _CallableModule(types.ModuleType):
|
|
def __call__(self, *args, **kwargs):
|
|
return page_index(*args, **kwargs)
|
|
|
|
|
|
sys.modules[__name__].__class__ = _CallableModule
|