Skip to content

Commit

Permalink
Use explicit arguments when calling string format.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmarren1 committed Dec 14, 2018
1 parent a1c8cd0 commit 343efc5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 36 deletions.
26 changes: 15 additions & 11 deletions dash/development/_py_components_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,26 @@ def __init__(self, {default_argtext}):
_locals.update(kwargs) # For wildcard attrs
args = {{k: _locals[k] for k in _explicit_args if k != 'children'}}
for k in {required_args}:
for k in {required_props}:
if k not in args:
raise TypeError(
'Required argument `' + k + '` was not specified.')
super({typename}, self).__init__({argtext})
'''

filtered_props = reorder_props(filter_props(props))
# pylint: disable=unused-variable
list_of_valid_wildcard_attr_prefixes = repr(parse_wildcards(props))
# pylint: disable=unused-variable
wildcard_prefixes = repr(parse_wildcards(props))
list_of_valid_keys = repr(list(map(str, filtered_props.keys())))
# pylint: disable=unused-variable
docstring = create_docstring(
component_name=typename,
props=filtered_props,
events=parse_events(props),
description=description).replace('\r\n', '\n')

# pylint: disable=unused-variable
events = '[' + ', '.join(parse_events(props)) + ']'
prop_keys = list(props.keys())
if 'children' in props:
prop_keys.remove('children')
default_argtext = "children=None, "
# pylint: disable=unused-variable
argtext = 'children=children, **args'
else:
default_argtext = ""
Expand All @@ -99,11 +93,21 @@ def __init__(self, {default_argtext}):
for p in prop_keys
if not p.endswith("-*") and
p not in kwlist and
p not in ['dashEvents', 'fireEvent', 'setProps']] + ['**kwargs']
p not in ['dashEvents', 'fireEvent', 'setProps']] + ["**kwargs"]
)

required_args = required_props(props)
return c.format(**locals())
return c.format(
typename=typename,
namespace=namespace,
filtered_props=filtered_props,
list_of_valid_wildcard_attr_prefixes=wildcard_prefixes,
list_of_valid_keys=list_of_valid_keys,
docstring=docstring,
events=events,
default_argtext=default_argtext,
argtext=argtext,
required_props=required_args
)


def generate_class_file(typename, props, description, namespace):
Expand Down
27 changes: 2 additions & 25 deletions tests/development/metadata_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def __init__(self, children=None, optionalArray=Component.UNDEFINED, optionalBoo
self._prop_names = ['children', 'optionalArray', 'optionalBool', 'optionalNumber', 'optionalObject', 'optionalString', 'optionalNode', 'optionalElement', 'optionalEnum', 'optionalUnion', 'optionalArrayOf', 'optionalObjectOf', 'optionalObjectWithShapeAndNestedDescription', 'optionalAny', 'customProp', 'customArrayProp', 'data-*', 'aria-*', 'in', 'id']
self._type = 'Table'
self._namespace = 'TableComponents'
self._valid_wildcard_attributes = ['data-', 'aria-']
self._valid_wildcard_attributes = ['data-', 'aria-']
self.available_events = ['restyle', 'relayout', 'click']
self.available_properties = ['children', 'optionalArray', 'optionalBool', 'optionalNumber', 'optionalObject', 'optionalString', 'optionalNode', 'optionalElement', 'optionalEnum', 'optionalUnion', 'optionalArrayOf', 'optionalObjectOf', 'optionalObjectWithShapeAndNestedDescription', 'optionalAny', 'customProp', 'customArrayProp', 'data-*', 'aria-*', 'in', 'id']
self.available_wildcard_properties = ['data-', 'aria-']
self.available_wildcard_properties = ['data-', 'aria-']

_explicit_args = kwargs.pop('_explicit_args')
_locals = locals()
Expand All @@ -58,26 +58,3 @@ def __init__(self, children=None, optionalArray=Component.UNDEFINED, optionalBoo
raise TypeError(
'Required argument `' + k + '` was not specified.')
super(Table, self).__init__(children=children, **args)

def __repr__(self):
if(any(getattr(self, c, None) is not None
for c in self._prop_names
if c is not self._prop_names[0])
or any(getattr(self, c, None) is not None
for c in self.__dict__.keys()
if any(c.startswith(wc_attr)
for wc_attr in self._valid_wildcard_attributes))):
props_string = ', '.join([c+'='+repr(getattr(self, c, None))
for c in self._prop_names
if getattr(self, c, None) is not None])
wilds_string = ', '.join([c+'='+repr(getattr(self, c, None))
for c in self.__dict__.keys()
if any([c.startswith(wc_attr)
for wc_attr in
self._valid_wildcard_attributes])])
return ('Table(' + props_string +
(', ' + wilds_string if wilds_string != '' else '') + ')')
else:
return (
'Table(' +
repr(getattr(self, self._prop_names[0], None)) + ')')

0 comments on commit 343efc5

Please sign in to comment.