Skip to content

Commit

Permalink
feat: adding type annotations to some constructor parameters
Browse files Browse the repository at this point in the history
Using `get_typing_type` from `codegen/datatypes.py` to add Python
datatype to some constructor parameters.

Notes:

1.  Does not handle the `compound` datatype yet. `get_typing_type`
    raises a `ValueError` because it doesn't have a clause for this
    type; `add_constructor_params` catches this and simply doesn't add
    a type definition. Something between a third and half of all
    constructor parameters suffer from this, so we need to figure out
    what `compound` means and define a type for it.
2.  Almost all parameters are nullable, so the type is defined as
    (for example) `int` but the default value assigned is `None`.
  • Loading branch information
gvwilson committed Feb 3, 2025
1 parent dbbbaa8 commit 693cd5e
Show file tree
Hide file tree
Showing 1,010 changed files with 15,648 additions and 15,644 deletions.
8 changes: 6 additions & 2 deletions packages/python/plotly/codegen/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,14 @@ def add_constructor_params(
{extra}=None"""
)

for i, subtype_node in enumerate(subtype_nodes):
for subtype_node in subtype_nodes:
try:
py_type = f": {get_typing_type(subtype_node.datatype)}"
except ValueError: # FIXME
py_type = ""
buffer.write(
f""",
{subtype_node.name_property}=None"""
{subtype_node.name_property}{py_type}=None"""
)

for extra in append_extras:
Expand Down
126 changes: 63 additions & 63 deletions packages/python/plotly/plotly/graph_objs/_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2107,80 +2107,80 @@ def _prop_descriptions(self):
"""
def __init__(self,
arg=None,
alignmentgroup=None,
base=None,
basesrc=None,
cliponaxis=None,
constraintext=None,
customdata=None,
customdatasrc=None,
dx=None,
dy=None,
alignmentgroup: str=None,
base: Any=None,
basesrc: str=None,
cliponaxis: bool=None,
constraintext: Any=None,
customdata: numpy.ndarray=None,
customdatasrc: str=None,
dx: int|float=None,
dy: int|float=None,
error_x=None,
error_y=None,
hoverinfo=None,
hoverinfosrc=None,
hoverinfo: Any=None,
hoverinfosrc: str=None,
hoverlabel=None,
hovertemplate=None,
hovertemplatesrc=None,
hovertext=None,
hovertextsrc=None,
ids=None,
idssrc=None,
insidetextanchor=None,
hovertemplate: str=None,
hovertemplatesrc: str=None,
hovertext: str=None,
hovertextsrc: str=None,
ids: numpy.ndarray=None,
idssrc: str=None,
insidetextanchor: Any=None,
insidetextfont=None,
legend=None,
legendgroup=None,
legend: str=None,
legendgroup: str=None,
legendgrouptitle=None,
legendrank=None,
legendwidth=None,
legendrank: int|float=None,
legendwidth: int|float=None,
marker=None,
meta=None,
metasrc=None,
name=None,
offset=None,
offsetgroup=None,
offsetsrc=None,
opacity=None,
orientation=None,
meta: Any=None,
metasrc: str=None,
name: str=None,
offset: int|float=None,
offsetgroup: str=None,
offsetsrc: str=None,
opacity: int|float=None,
orientation: Any=None,
outsidetextfont=None,
selected=None,
selectedpoints=None,
showlegend=None,
selectedpoints: Any=None,
showlegend: bool=None,
stream=None,
text=None,
textangle=None,
text: str=None,
textangle: int|float=None,
textfont=None,
textposition=None,
textpositionsrc=None,
textsrc=None,
texttemplate=None,
texttemplatesrc=None,
uid=None,
uirevision=None,
textposition: Any=None,
textpositionsrc: str=None,
textsrc: str=None,
texttemplate: str=None,
texttemplatesrc: str=None,
uid: str=None,
uirevision: Any=None,
unselected=None,
visible=None,
width=None,
widthsrc=None,
x=None,
x0=None,
xaxis=None,
xcalendar=None,
xhoverformat=None,
xperiod=None,
xperiod0=None,
xperiodalignment=None,
xsrc=None,
y=None,
y0=None,
yaxis=None,
ycalendar=None,
yhoverformat=None,
yperiod=None,
yperiod0=None,
yperiodalignment=None,
ysrc=None,
zorder=None,
visible: Any=None,
width: int|float=None,
widthsrc: str=None,
x: numpy.ndarray=None,
x0: Any=None,
xaxis: str=None,
xcalendar: Any=None,
xhoverformat: str=None,
xperiod: Any=None,
xperiod0: Any=None,
xperiodalignment: Any=None,
xsrc: str=None,
y: numpy.ndarray=None,
y0: Any=None,
yaxis: str=None,
ycalendar: Any=None,
yhoverformat: str=None,
yperiod: Any=None,
yperiod0: Any=None,
yperiodalignment: Any=None,
ysrc: str=None,
zorder: int=None,
**kwargs
):
"""
Expand Down
82 changes: 41 additions & 41 deletions packages/python/plotly/plotly/graph_objs/_barpolar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,53 +1299,53 @@ def _prop_descriptions(self):
"""
def __init__(self,
arg=None,
base=None,
basesrc=None,
customdata=None,
customdatasrc=None,
dr=None,
dtheta=None,
hoverinfo=None,
hoverinfosrc=None,
base: Any=None,
basesrc: str=None,
customdata: numpy.ndarray=None,
customdatasrc: str=None,
dr: int|float=None,
dtheta: int|float=None,
hoverinfo: Any=None,
hoverinfosrc: str=None,
hoverlabel=None,
hovertemplate=None,
hovertemplatesrc=None,
hovertext=None,
hovertextsrc=None,
ids=None,
idssrc=None,
legend=None,
legendgroup=None,
hovertemplate: str=None,
hovertemplatesrc: str=None,
hovertext: str=None,
hovertextsrc: str=None,
ids: numpy.ndarray=None,
idssrc: str=None,
legend: str=None,
legendgroup: str=None,
legendgrouptitle=None,
legendrank=None,
legendwidth=None,
legendrank: int|float=None,
legendwidth: int|float=None,
marker=None,
meta=None,
metasrc=None,
name=None,
offset=None,
offsetsrc=None,
opacity=None,
r=None,
r0=None,
rsrc=None,
meta: Any=None,
metasrc: str=None,
name: str=None,
offset: int|float=None,
offsetsrc: str=None,
opacity: int|float=None,
r: numpy.ndarray=None,
r0: Any=None,
rsrc: str=None,
selected=None,
selectedpoints=None,
showlegend=None,
selectedpoints: Any=None,
showlegend: bool=None,
stream=None,
subplot=None,
text=None,
textsrc=None,
theta=None,
theta0=None,
thetasrc=None,
thetaunit=None,
uid=None,
uirevision=None,
subplot: str=None,
text: str=None,
textsrc: str=None,
theta: numpy.ndarray=None,
theta0: Any=None,
thetasrc: str=None,
thetaunit: Any=None,
uid: str=None,
uirevision: Any=None,
unselected=None,
visible=None,
width=None,
widthsrc=None,
visible: Any=None,
width: int|float=None,
widthsrc: str=None,
**kwargs
):
"""
Expand Down
Loading

0 comments on commit 693cd5e

Please sign in to comment.