I am not sure if this is a bokeh bug, or I am confusing something, but I get the following warning from Pylance, when using this very minimal code:
Argument of type “Model” cannot be assigned to parameter “obj” of type “UIElement | Application | ModifyDoc” in function “show”
Type “Model” cannot be assigned to type “UIElement | Application | ModifyDoc”
“Model” is incompatible with “UIElement”
“Model” is incompatible with “Application”
Type “Model” cannot be assigned to type “ModifyDoc”
from bokeh.plotting import figure, show
p = figure()
show(p)
if I change the second line to p: figure = figure() I don’t get a warning in the last line, but a warning in the second line:
Expression of type “Model” cannot be assigned to declared type “figure”
“Model” is incompatible with “figure”
figure inherits from Plot which inherits from LayoutDOM which inherits from UIElement. So I have to conclude that the annotations are correct as given in the Bokeh source code, and would also note that mypy (which is run on the codebase continually on GitHub) is happy with this code:
dev-311 ❯ cat foo.py
from bokeh.plotting import figure, show
p = figure()
show(p)
dev-311 ❯ mypy foo.py
Success: no issues found in 1 source file
OTOH Bokeh models (like figure) have complicated metaclasses, so maybe there is something about that that confuses pylance. I don’t have any concrete suggestions, I am afraid.