MCPcopy
hub / github.com/plotly/dash / generate_class_string

Function generate_class_string

dash/development/_py_components_generation.py:48–230  ·  view source on GitHub ↗

Dynamically generate class strings to have nicely formatted docstrings, keyword arguments, and repr. Inspired by http://jameso.be/2013/08/06/namedtuple.html Parameters ---------- typename props description namespace prop_reorder_exceptions Returns -------

(
    typename,
    props,
    description,
    namespace,
    prop_reorder_exceptions=None,
    max_props=None,
    custom_typing_module=None,
)

Source from the content-addressed store, hash-verified

46
47# pylint: disable=unused-argument,too-many-locals,too-many-branches
48def generate_class_string(
49 typename,
50 props,
51 description,
52 namespace,
53 prop_reorder_exceptions=None,
54 max_props=None,
55 custom_typing_module=None,
56):
57 """Dynamically generate class strings to have nicely formatted docstrings,
58 keyword arguments, and repr.
59 Inspired by http://jameso.be/2013/08/06/namedtuple.html
60 Parameters
61 ----------
62 typename
63 props
64 description
65 namespace
66 prop_reorder_exceptions
67 Returns
68 -------
69 string
70 """
71 # TODO _prop_names, _type, _namespace, and available_properties
72 # can be modified by a Dash JS developer via setattr
73 # TODO - Tab out the repr for the repr of these components to make it
74 # look more like a hierarchical tree
75 # TODO - Include "description" "defaultValue" in the repr and docstring
76 #
77 # TODO - Handle "required"
78 #
79 # TODO - How to handle user-given `null` values? I want to include
80 # an expanded docstring like Dropdown(value=None, id=None)
81 # but by templating in those None values, I have no way of knowing
82 # whether a property is None because the user explicitly wanted
83 # it to be `null` or whether that was just the default value.
84 # The solution might be to deal with default values better although
85 # not all component authors will supply those.
86 c = '''class {typename}(Component):
87 """{docstring}"""
88 _children_props: typing.List[str] = {children_props}
89 _base_nodes = {base_nodes}
90 _namespace = '{namespace}'
91 _type = '{typename}'
92{shapes}
93
94 def __init__(
95 self,
96 {default_argtext}
97 ):
98 self._prop_names = {list_of_valid_keys}
99 self._valid_wildcard_attributes =\
100 {list_of_valid_wildcard_attr_prefixes}
101 self.available_properties = {list_of_valid_keys}
102 self.available_wildcard_properties =\
103 {list_of_valid_wildcard_attr_prefixes}
104 _explicit_args = kwargs.pop('_explicit_args')
105 _locals = locals()

Callers 3

generate_class_fileFunction · 0.70
generate_classFunction · 0.70

Calls 15

collect_nodesFunction · 0.90
filter_base_nodesFunction · 0.90
reorder_propsFunction · 0.85
parse_wildcardsFunction · 0.85
get_custom_ignoreFunction · 0.85
create_docstringFunction · 0.85
required_propsFunction · 0.85
prohibit_eventsFunction · 0.85
get_prop_typingFunction · 0.85
get_custom_propsFunction · 0.85
keysMethod · 0.80
filter_propsFunction · 0.70

Used in the wild real call sites across dependent graphs

searching dependent graphs…