panel icon indicating copy to clipboard operation
panel copied to clipboard

wrong type annotaions in pn.state.<callbacks>

Open bakkiaraj opened this issue 1 month ago • 0 comments

Python version: 3.12 Panel: 1.8.3 File: .venv/lib/python3.12/site-packages/panel/io/state.py

Issue: When I do following code,


def on_session_destroyed(session_context: BokehSessionContext) -> None:
    if session_context.request is not None:
        print(f' session destroyed at the {session_context.request.uri} endpoint with session ID: {session_context.id}')
...
pn.state.on_session_destroyed(callback=on_session_destroyed) 

I get type annotation issue

Image

At run time, session_context: is BokehSessionContext type and its documented in https://panel.holoviz.org/how_to/callbacks/session.html but the code panel/io/state.py do not have correct type annotations for call backs.

Expected behavior: Correct the callback function's type annotations.

Ex: in state.py

    def on_session_destroyed(self, callback: Callable[[SessionContext], None]) -> None:

should be

    def on_session_destroyed(self, callback: Callable[[BokehSessionContext ], None]) -> None:

bakkiaraj avatar Nov 26 '25 09:11 bakkiaraj