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

Added support for Marker descriptions #1

Merged
merged 1 commit into from
Mar 10, 2018

Conversation

svisser
Copy link
Contributor

@svisser svisser commented Feb 16, 2018

This adds support for Marker descriptions released yesterday in voluptuous 0.11.1 (alecthomas/voluptuous#307).

I'm callling str() on the description because people may use text-like objects for their descriptions in their schemas (probably rare).

else:
pkey = key

pval = convert(value)
pval['name'] = pkey
if description is not None:
pval['description'] = str(description)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should not do this. There is no predefined type of the description field and so we can't force one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you be okay with passing the description on as given?

if isinstance(key, vol.Marker):
pkey = key.schema
try:
description = key.description
except AttributeError:
Copy link
Collaborator

Choose a reason for hiding this comment

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

When would this raise an AttributeError ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

And if that is possible, let's add a test for it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

(I don't think it's possible, as you can see from my PR alecthomas/voluptuous#307): it's always set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's there because people may use an older version of voluptuous which doesn't yet have support for descriptions. I'm happy to add a test for it to ensure it can be handled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, the current test case would also fail in 0.10.5 or older. Would you want to make this project to be 0.11.1+ only or should it support older versions as well?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, good point. I made this lib for using it in Home Assistant, so let's see if I can update Home Assistant to use 0.11 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It appears you were able to upgrade to voluptuous 0.11.1? Any thoughts on whether you'd want this project to be 0.11.1+ only or to also support some older versions?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, was able to upgrade. Let's just stick with 0.11.1+.

@svisser svisser force-pushed the marker_description branch from b2ccaf6 to 4ed9c27 Compare March 10, 2018 15:33
@svisser
Copy link
Contributor Author

svisser commented Mar 10, 2018

Thanks, I have updated the commit to always assume description exists.

@balloob balloob merged commit 567f0d9 into home-assistant-libs:master Mar 10, 2018
@balloob
Copy link
Collaborator

balloob commented Mar 10, 2018

awesome! are you planning on using this?

@balloob
Copy link
Collaborator

balloob commented Mar 10, 2018

If you are, I have a webcomponent here that can render these forms (or some parts of it).

I also plan on adding a hook to allow people to define serialization strategies for custom validators.

@svisser
Copy link
Contributor Author

svisser commented Mar 10, 2018

Yeah, I'll need to upgrade to voluptuous 0.11.1 as well first.

I do have a use for this project as in one project I'm now maintaining both the schema and a separate description of that schema. Some functionality is still missing though, such as support for Any(), Maybe() and possibly other validators.

@balloob
Copy link
Collaborator

balloob commented Mar 11, 2018

Cool! I literally just added enough for the needs of Home Assistant.

@svisser svisser deleted the marker_description branch March 11, 2018 20:18
@awarecan
Copy link
Contributor

awarecan commented Jul 7, 2018

@balloob this PR has not been released to PyPi. We could use it to enhance our login form right away.

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.

3 participants