Skip to content

Commit 343efc5

Browse files
committed
Use explicit arguments when calling string format.
1 parent a1c8cd0 commit 343efc5

File tree

2 files changed

+17
-36
lines changed

2 files changed

+17
-36
lines changed

Diff for: dash/development/_py_components_generation.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -62,32 +62,26 @@ def __init__(self, {default_argtext}):
6262
_locals.update(kwargs) # For wildcard attrs
6363
args = {{k: _locals[k] for k in _explicit_args if k != 'children'}}
6464
65-
for k in {required_args}:
65+
for k in {required_props}:
6666
if k not in args:
6767
raise TypeError(
6868
'Required argument `' + k + '` was not specified.')
6969
super({typename}, self).__init__({argtext})
7070
'''
7171

7272
filtered_props = reorder_props(filter_props(props))
73-
# pylint: disable=unused-variable
74-
list_of_valid_wildcard_attr_prefixes = repr(parse_wildcards(props))
75-
# pylint: disable=unused-variable
73+
wildcard_prefixes = repr(parse_wildcards(props))
7674
list_of_valid_keys = repr(list(map(str, filtered_props.keys())))
77-
# pylint: disable=unused-variable
7875
docstring = create_docstring(
7976
component_name=typename,
8077
props=filtered_props,
8178
events=parse_events(props),
8279
description=description).replace('\r\n', '\n')
83-
84-
# pylint: disable=unused-variable
8580
events = '[' + ', '.join(parse_events(props)) + ']'
8681
prop_keys = list(props.keys())
8782
if 'children' in props:
8883
prop_keys.remove('children')
8984
default_argtext = "children=None, "
90-
# pylint: disable=unused-variable
9185
argtext = 'children=children, **args'
9286
else:
9387
default_argtext = ""
@@ -99,11 +93,21 @@ def __init__(self, {default_argtext}):
9993
for p in prop_keys
10094
if not p.endswith("-*") and
10195
p not in kwlist and
102-
p not in ['dashEvents', 'fireEvent', 'setProps']] + ['**kwargs']
96+
p not in ['dashEvents', 'fireEvent', 'setProps']] + ["**kwargs"]
10397
)
104-
10598
required_args = required_props(props)
106-
return c.format(**locals())
99+
return c.format(
100+
typename=typename,
101+
namespace=namespace,
102+
filtered_props=filtered_props,
103+
list_of_valid_wildcard_attr_prefixes=wildcard_prefixes,
104+
list_of_valid_keys=list_of_valid_keys,
105+
docstring=docstring,
106+
events=events,
107+
default_argtext=default_argtext,
108+
argtext=argtext,
109+
required_props=required_args
110+
)
107111

108112

109113
def generate_class_file(typename, props, description, namespace):

Diff for: tests/development/metadata_test.py

+2-25
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ def __init__(self, children=None, optionalArray=Component.UNDEFINED, optionalBoo
4343
self._prop_names = ['children', 'optionalArray', 'optionalBool', 'optionalNumber', 'optionalObject', 'optionalString', 'optionalNode', 'optionalElement', 'optionalEnum', 'optionalUnion', 'optionalArrayOf', 'optionalObjectOf', 'optionalObjectWithShapeAndNestedDescription', 'optionalAny', 'customProp', 'customArrayProp', 'data-*', 'aria-*', 'in', 'id']
4444
self._type = 'Table'
4545
self._namespace = 'TableComponents'
46-
self._valid_wildcard_attributes = ['data-', 'aria-']
46+
self._valid_wildcard_attributes = ['data-', 'aria-']
4747
self.available_events = ['restyle', 'relayout', 'click']
4848
self.available_properties = ['children', 'optionalArray', 'optionalBool', 'optionalNumber', 'optionalObject', 'optionalString', 'optionalNode', 'optionalElement', 'optionalEnum', 'optionalUnion', 'optionalArrayOf', 'optionalObjectOf', 'optionalObjectWithShapeAndNestedDescription', 'optionalAny', 'customProp', 'customArrayProp', 'data-*', 'aria-*', 'in', 'id']
49-
self.available_wildcard_properties = ['data-', 'aria-']
49+
self.available_wildcard_properties = ['data-', 'aria-']
5050

5151
_explicit_args = kwargs.pop('_explicit_args')
5252
_locals = locals()
@@ -58,26 +58,3 @@ def __init__(self, children=None, optionalArray=Component.UNDEFINED, optionalBoo
5858
raise TypeError(
5959
'Required argument `' + k + '` was not specified.')
6060
super(Table, self).__init__(children=children, **args)
61-
62-
def __repr__(self):
63-
if(any(getattr(self, c, None) is not None
64-
for c in self._prop_names
65-
if c is not self._prop_names[0])
66-
or any(getattr(self, c, None) is not None
67-
for c in self.__dict__.keys()
68-
if any(c.startswith(wc_attr)
69-
for wc_attr in self._valid_wildcard_attributes))):
70-
props_string = ', '.join([c+'='+repr(getattr(self, c, None))
71-
for c in self._prop_names
72-
if getattr(self, c, None) is not None])
73-
wilds_string = ', '.join([c+'='+repr(getattr(self, c, None))
74-
for c in self.__dict__.keys()
75-
if any([c.startswith(wc_attr)
76-
for wc_attr in
77-
self._valid_wildcard_attributes])])
78-
return ('Table(' + props_string +
79-
(', ' + wilds_string if wilds_string != '' else '') + ')')
80-
else:
81-
return (
82-
'Table(' +
83-
repr(getattr(self, self._prop_names[0], None)) + ')')

0 commit comments

Comments
 (0)