Description
I am seeing a false-positive type-checking error in Pylance/Pyright when I use a documented numeric format string with text_auto in Plotly Express.
This report specifically concerns plotly.express.bar (the px.bar function exposed by import plotly.express as px), whose text_auto parameter is inferred as bool by Pylance/Pyright.
The runtime behavior is correct, and the documentation states that text_auto accepts either a boolean or a string. A string such as ".2f" is interpreted as a numeric texttemplate formatting directive.
Steps to reproduce
import plotly.express as px
media_disciplina = {
"disciplina": ["Math", "Science"],
"media": [8.5, 7.2],
}
fig = px.bar(
media_disciplina,
x="disciplina",
y="media",
title="Average by subject",
text_auto=".1f",
)
Pylance reports:
Argument of type "Literal['.1f']" cannot be assigned to parameter "text_auto" of type "bool" in function "bar"
Expected behavior
Static type checking should accept both bool and str for text_auto, matching the documented and runtime API.
Notes
The current function signature uses an unannotated default:
Pylance/Pyright therefore infers the parameter as bool from its default value.
Could the Plotly Express functions that expose text_auto be annotated as accepting both supported values? For compatibility with older Python versions, an annotation such as the following would address this:
from typing import Union
text_auto: Union[bool, str] = False
If this is an appropriate change, I would be happy to submit a pull request.
Description
I am seeing a false-positive type-checking error in Pylance/Pyright when I use a documented numeric format string with
text_autoin Plotly Express.This report specifically concerns
plotly.express.bar(thepx.barfunction exposed byimport plotly.express as px), whosetext_autoparameter is inferred asboolby Pylance/Pyright.The runtime behavior is correct, and the documentation states that
text_autoaccepts either a boolean or a string. A string such as".2f"is interpreted as a numerictexttemplateformatting directive.Steps to reproduce
Pylance reports:
Expected behavior
Static type checking should accept both
boolandstrfortext_auto, matching the documented and runtime API.Notes
The current function signature uses an unannotated default:
Pylance/Pyright therefore infers the parameter as
boolfrom its default value.Could the Plotly Express functions that expose
text_autobe annotated as accepting both supported values? For compatibility with older Python versions, an annotation such as the following would address this:If this is an appropriate change, I would be happy to submit a pull request.