Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Props blacklist #753

Merged
merged 8 commits into from
May 30, 2019
Merged

Props blacklist #753

merged 8 commits into from
May 30, 2019

Conversation

alexcjohnson
Copy link
Collaborator

@alexcjohnson alexcjohnson commented May 30, 2019

Fixes plotly/dash-core-components#440

Pares down the attributes of dash component classes on the Python side by doing two things:

  • Remove the MutableMapping inheritance - we weren't using any of the mixins from that class anyway, except in tests. This stops setting attributes: clear, get, items, keys, pop, popitem, setdefault, update, values - all of these are now allowable as prop names. We still set the magic methods of the mapping interface.
  • Prefix a couple of other methods (traverse and traverse_with_paths) with underscores, so these are allowable as well.

Then what's left we blacklist: during extract-meta, if any prop has a leading underscore or matches one of the remaining disallowed names, we fail (not just print a warning) and refuse to generate the python file. The names we forbid are:

  • UNDEFINED
  • REQUIRED
  • to_plotly_json
  • available_properties
  • available_wildcard_properties

These are all used within generated components, or (in the case of to_plotly_json) in other packages, so it would be difficult to allow these without forcing all packages to be rebuilt. Fortunately I don't see these as particularly valuable prop names (unlike, say, values, items, and some of the other MutableMapping methods)

Error messages look like:

ERROR: "_foo" matches forbidden prop name pattern: /^_.*$/

extract-meta failed.


Error generating metadata in dash_core_components (status=0)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
...
  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR
  • I have added entry in the CHANGELOG.md


c1 = Component(id='1')
c2 = Component(id='2', children=[Component()])
self.assertTrue(c1 == c2)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of a nice side effect, IMO, that components are now no longer always equal to each other - though I don't know why this would come up...

@@ -487,8 +489,7 @@ def test_iter(self):

class TestGenerateClassFile(unittest.TestCase):
def setUp(self):
json_path = os.path.join(
'tests', 'unit', 'dash', 'development', 'metadata_test.json')
json_path = os.path.join(_dir, 'metadata_test.json')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that you can run the tests from any working directory, not just the repo root.

}
else {
writeOut(metadata);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't write a response if the error was severe enough for us to set failed - this causes generate_components to fail as well.

Copy link
Contributor

@byronz byronz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃 looks great, thanks Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dcc.Checklist() gives error loading layout
2 participants