Skip to content

Commit af3d13f

Browse files
committed
Fix: Defer TableWidget import to prevent ZMQ port conflicts
1 parent 719b278 commit af3d13f

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

bigframes/display/__init__.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,24 @@
1616

1717
from __future__ import annotations
1818

19-
try:
20-
import anywidget # noqa
19+
from typing import Any
2120

22-
from bigframes.display.anywidget import TableWidget
2321

24-
__all__ = ["TableWidget"]
25-
except Exception:
26-
pass
22+
def __getattr__(name: str) -> Any:
23+
if name == "TableWidget":
24+
try:
25+
import anywidget # noqa
26+
27+
from bigframes.display.anywidget import TableWidget
28+
29+
return TableWidget
30+
except Exception:
31+
raise AttributeError(
32+
f"module '{__name__}' has no attribute '{name}'. "
33+
"TableWidget requires anywidget and traitlets to be installed. "
34+
"Please `pip install anywidget traitlets` or `pip install 'bigframes[anywidget]'`."
35+
)
36+
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
37+
38+
39+
__all__ = ["TableWidget"]

0 commit comments

Comments
 (0)