Skip to content

Commit cd660ba

Browse files
committed
Make all props after id keyword only
1 parent d9744ea commit cd660ba

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

justfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,10 @@ _move-generated-files:
137137
if file_.name in ("__init__.py", "_table.py", "_version.py", "icons.py", "themes.py"):
138138
continue
139139
filename = "__init__.py" if file_.name == "_imports_.py" else file_.name
140-
file_.rename(file_.parent / "_components" / filename)
140+
new_file = file_.parent / "_components" / filename
141+
file_.rename(new_file)
142+
# enforce keyword arguments only after the id argument
143+
id_pattern = " id: typing.Optional[str] = None,\n"
144+
new_file.write_text(
145+
new_file.read_text().replace(id_pattern, f"{id_pattern}{8 * ' '}*,\n")
146+
)

tests/test_positional_args.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
import inspect
2+
3+
import dash_bootstrap_components as dbc
4+
import pytest
15
from dash import Dash, html
2-
from dash_bootstrap_components import Checklist, RadioItems, Select
6+
from dash_bootstrap_components._components import __all__ as COMPONENT_NAMES
37
from selenium.webdriver.common.by import By
48

59

610
def test_dbpa001_checklist(dash_duo):
711
"""
8-
Check that the options and value positional arguments are working for
9-
Checklist.
12+
Check that the options and value positional arguments are working for dbc.Checklist.
1013
"""
1114
app = Dash()
1215

@@ -18,12 +21,12 @@ def test_dbpa001_checklist(dash_duo):
1821

1922
value = "OptionB"
2023

21-
with_keywords = Checklist(
24+
with_keywords = dbc.Checklist(
2225
options=options,
2326
value=value,
2427
id="with-keywords",
2528
)
26-
without_keywords = Checklist(options, value, id="without-keywords")
29+
without_keywords = dbc.Checklist(options, value, id="without-keywords")
2730

2831
app.layout = html.Div([with_keywords, without_keywords])
2932

@@ -59,7 +62,7 @@ def test_dbpa001_checklist(dash_duo):
5962
def test_dbpa002_radio_items(dash_duo):
6063
"""
6164
Check that the options and value positional arguments are working for
62-
RadioItems.
65+
dbc.RadioItems.
6366
"""
6467
app = Dash()
6568

@@ -71,12 +74,12 @@ def test_dbpa002_radio_items(dash_duo):
7174

7275
value = "OptionB"
7376

74-
with_keywords = RadioItems(
77+
with_keywords = dbc.RadioItems(
7578
options=options,
7679
value=value,
7780
id="with-keywords",
7881
)
79-
without_keywords = RadioItems(options, value, id="without-keywords")
82+
without_keywords = dbc.RadioItems(options, value, id="without-keywords")
8083

8184
app.layout = html.Div([with_keywords, without_keywords])
8285

@@ -111,8 +114,7 @@ def test_dbpa002_radio_items(dash_duo):
111114

112115
def test_dbpa003_select(dash_duo):
113116
"""
114-
Check that the options and value positional arguments are working for
115-
Select.
117+
Check that the options and value positional arguments are working for dbc.Select.
116118
"""
117119
app = Dash()
118120

@@ -124,12 +126,12 @@ def test_dbpa003_select(dash_duo):
124126

125127
value = "OptionB"
126128

127-
with_keywords = Select(
129+
with_keywords = dbc.Select(
128130
options=options,
129131
value=value,
130132
id="with-keywords",
131133
)
132-
without_keywords = Select(options, value, id="without-keywords")
134+
without_keywords = dbc.Select(options, value, id="without-keywords")
133135

134136
app.layout = html.Div([with_keywords, without_keywords])
135137

@@ -160,3 +162,21 @@ def test_dbpa003_select(dash_duo):
160162
by=By.TAG_NAME, value="option"
161163
)
162164
]
165+
166+
167+
@pytest.mark.parametrize("component_name", COMPONENT_NAMES)
168+
def test_dbpa004_keyword_only_args(component_name):
169+
component = getattr(dbc, component_name)
170+
signature = inspect.signature(component)
171+
id_seen = False
172+
for name, param in signature.parameters.items():
173+
if name == "id":
174+
id_seen = True
175+
elif id_seen:
176+
# all parameters after the id should be keyword only or **kwargs
177+
assert param.kind in (
178+
inspect.Parameter.KEYWORD_ONLY,
179+
inspect.Parameter.VAR_KEYWORD,
180+
)
181+
182+
assert id_seen

0 commit comments

Comments
 (0)