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

Update voluputous #12463

Merged
merged 8 commits into from
Feb 17, 2018
Merged

Update voluputous #12463

merged 8 commits into from
Feb 17, 2018

Conversation

balloob
Copy link
Member

@balloob balloob commented Feb 16, 2018

Bump voluptuous to 0.11.1

Note for breaking change
Custom components only: voluptuous now requires default values for config keys to be valid values.

[0.11.0]

Changes:

  • #293: Support Python 3.6.
  • #294: Drop support for Python 2.6, 3.1 and 3.2.
  • #318: Allow to use nested schema and allow any validator to be compiled.
  • #324:
    Default values MUST now pass validation just as any regular value. This is a backward incompatible change if a schema uses default values that don't pass validation against the specified schema.
  • #328:
    Modify __lt__ in Marker class to allow comparison with non Marker objects, such as str and int.

New:

  • #307: Add description field to Marker instances.
  • #311: Add Schema.infer method for basic schema inference.
  • #314: Add SomeOf validator.

Fixes:

  • #279:
    Treat Python 2 old-style classes like types when validating.
  • #280: Make
    IsDir(), IsFile() and PathExists() consistent between different Python versions.
  • #290: Use absolute imports to avoid import conflicts.
  • #291: Fix Coerce validator to catch decimal.InvalidOperation.
  • #298: Make Schema([]) usage consistent with Schema({}).
  • #303: Allow partial validation when using validate decorator.
  • #316: Make Schema.__eq__ deterministic.
  • #319: Replace implementation of Maybe(s) with Any(None, s) to allow it to be compiled.

@balloob balloob requested review from andrey-git and a team as code owners February 16, 2018 20:58
@homeassistant homeassistant added cla-signed core small-pr PRs with less than 30 lines. labels Feb 16, 2018
@andrey-git
Copy link
Contributor

We must be careful with Default values MUST now pass validation just as any regular value. This could break any platform, and if not a built-in platform then any custom component.

@balloob
Copy link
Member Author

balloob commented Feb 16, 2018

I know. Was waiting for Travis to tell me what needs work. We should rip this bandaid off 👍

@pvizeli
Copy link
Member

pvizeli commented Feb 16, 2018

I like this new feature but it have also break some stuff on hass.io :)

@balloob
Copy link
Member Author

balloob commented Feb 16, 2018

I did a first pass looking for all the vol.Optional('', default=None) and found a bunch.

Next up I'm going to modify voluptuous locally to validate default while constructing schemas, load every file and find final defaults that are wrong.

@balloob
Copy link
Member Author

balloob commented Feb 16, 2018

To patch voluptuous, add this to the end of the Schema constructor:

        if not isinstance(schema, dict):
            return

        for key, value in schema.items():
            if not hasattr(key, 'default'):
                continue

            if key.default is UNDEFINED:
                continue

            default = key.default

            if callable(default):
                default = default()

            try:
                Schema(value)(default)
            except Exception as err:
                print(f'{default} did not match {value}: {err}')

Then change script/gen_requirements.py and add print(package) above the line module = importlib.import_module(package)

@balloob
Copy link
Member Author

balloob commented Feb 17, 2018

Making tons of progress. Just the tests left.

Found a voluptuous 0.11 incompatible schema in one of our dependencies using voluptuous: emlove/aioautomatic#4

@balloob
Copy link
Member Author

balloob commented Feb 17, 2018

Done 🎉

Copy link
Member

@pvizeli pvizeli left a comment

Choose a reason for hiding this comment

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

Amazing. Make the code a lot better and fix really strange stuff :( they going out of scope by reviews

@pvizeli pvizeli merged commit 3fd61d8 into dev Feb 17, 2018
@pvizeli pvizeli deleted the update-voluptuous branch February 17, 2018 09:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants