Skip to content

Commit 5fffe7e

Browse files
committed
Add ignore_props config to dash_prop_typing
1 parent 87e439a commit 5fffe7e

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

dash/development/_generate_prop_types.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import os
66
import re
77

8+
from dash.development._py_prop_typing import get_custom_ignore
9+
810

911
init_check_re = re.compile("proptypes.js")
1012

@@ -120,9 +122,12 @@ def check_init(namespace):
120122
def generate_prop_types(
121123
metadata,
122124
package_name,
125+
custom_typing_module,
123126
):
124127
patched = []
125128

129+
custom_ignore = get_custom_ignore(custom_typing_module)
130+
126131
for component_path, data in metadata.items():
127132
filename = component_path.split("/")[-1]
128133
extension = filename.split("/")[-1].split(".")[-1]
@@ -133,7 +138,11 @@ def generate_prop_types(
133138

134139
props = []
135140
for prop_name, prop_data in data.get("props", {}).items():
136-
props.append(f"{prop_name}:{generate_prop_type(prop_data['type'])}")
141+
if prop_name in custom_ignore:
142+
prop_type = "pt.any"
143+
else:
144+
prop_type = generate_prop_type(prop_data["type"])
145+
props.append(f"{prop_name}:{prop_type}")
137146

138147
patched.append(
139148
component_prop_types_template.format(

dash/development/_py_components_generation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from ._all_keywords import python_keywords
1212
from ._collect_nodes import collect_nodes, filter_base_nodes
1313
from ._py_prop_typing import (
14+
get_custom_ignore,
1415
get_custom_props,
1516
get_prop_typing,
1617
shapes,
@@ -150,6 +151,8 @@ def __init__(
150151

151152
default_arglist = []
152153

154+
custom_ignore = get_custom_ignore(custom_typing_module)
155+
153156
for prop_key in prop_keys:
154157
prop = props[prop_key]
155158
if (
@@ -175,6 +178,7 @@ def __init__(
175178
prop_key,
176179
type_info,
177180
custom_props=custom_props,
181+
custom_ignore=custom_ignore,
178182
)
179183

180184
arg_value = f"{prop_key}: typing.Optional[{typed}] = None"

dash/development/_py_prop_typing.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ def get_custom_props(module_name):
3434
return _get_custom(module_name, "custom_props", {})
3535

3636

37+
def get_custom_ignore(module_name):
38+
return _get_custom(module_name, "ignore_props", ["style"])
39+
40+
3741
def _clean_key(key):
3842
k = ""
3943
for ch in key:
@@ -142,6 +146,7 @@ def get_prop_typing(
142146
prop_name: str,
143147
type_info,
144148
custom_props=None,
149+
custom_ignore=None,
145150
):
146151
if prop_name == "id":
147152
# Id is always the same either a string or a dict for pattern matching.
@@ -152,6 +157,9 @@ def get_prop_typing(
152157
if special:
153158
return special(type_info, component_name, prop_name)
154159

160+
if custom_ignore and prop_name in custom_ignore:
161+
return "typing.Any"
162+
155163
prop_type = PROP_TYPING.get(type_name, generate_any)(
156164
type_info, component_name, prop_name
157165
)

dash/development/component_generator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,11 @@ def generate_components(
139139

140140
components = generate_classes_files(project_shortname, metadata, *generator_methods)
141141

142-
generate_prop_types(metadata, project_shortname)
142+
generate_prop_types(
143+
metadata,
144+
project_shortname,
145+
custom_typing_module=custom_typing_module,
146+
)
143147

144148
with open(
145149
os.path.join(project_shortname, "metadata.json"), "w", encoding="utf-8"

0 commit comments

Comments
 (0)