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

Modified __lt__ in Marker class. #328

Merged
merged 1 commit into from
Feb 14, 2018
Merged

Conversation

Mo2000
Copy link

@Mo2000 Mo2000 commented Feb 14, 2018

Marker class in /voluptuous/schema_builder.py needed to have the __lt__() function
modified in order to compare against regular strings as well.

This will allow the usage of Voluptuous Optional objects as keys in dicts alongside
strings and int.

An example of this would be a dict as such:

{
    'Name': <function is_str at 0x1057b8b90>,
    'ExecutionTimestamp': <function is_str at 0x1057b8b90>,
    Optional('Classification'): [Any([<function is_str at 0x1057b8b90>, <function is_null at 0x1057b8aa0>])]
}

Sorting the above dict without the proposed changes will result in an error similar to the one below:

  File "/Users/mo2000/Work/QA/venv/lib/python2.7/site-packages/voluptuous/schema_builder.py", line 902, in __lt__
    return self.schema < other.schema

@coveralls
Copy link

coveralls commented Feb 14, 2018

Coverage Status

Coverage decreased (-0.09%) to 95.17% when pulling 826c4ae on Mo2000:master into a206303 on alecthomas:master.

@coveralls
Copy link

coveralls commented Feb 14, 2018

Coverage Status

Coverage increased (+0.009%) to 95.265% when pulling f170fa7 on Mo2000:master into a206303 on alecthomas:master.

@alecthomas
Copy link
Owner

Can you add a test for this please?

@Mo2000 Mo2000 force-pushed the master branch 5 times, most recently from c35c76a to 7c7caca Compare February 14, 2018 02:15
Marker class in /voluptuous/schema_builder.py needed to have the __lt__() function
modified in order to compare against regular strings as well.

This will allow the usage of Voluptuous Optional objects as keys in dicts alongside
strings and int.
@Mo2000
Copy link
Author

Mo2000 commented Feb 14, 2018

Test has been added

@alecthomas
Copy link
Owner

Thanks!

@alecthomas alecthomas merged commit 2f2c778 into alecthomas:master Feb 14, 2018
wip-sync pushed a commit to NetBSD/pkgsrc-wip that referenced this pull request Aug 13, 2019
Upstream changes are many minor improvements and bugfixes, plus

**Changes**

- [#378](alecthomas/voluptuous#378): Allow `extend()` of a `Schema` to return a subclass of a `Schema` as well.

**Changes**:

- [#349](alecthomas/voluptuous#349): Support Python 3.7.
- [#343](alecthomas/voluptuous#343): Drop support for Python 3.3.

**Changes**:

- [#293](alecthomas/voluptuous#293): Support Python 3.6.
- [#294](alecthomas/voluptuous#294): Drop support for Python 2.6, 3.1 and 3.2.
- [#318](alecthomas/voluptuous#318): Allow to use nested schema and allow any validator to be compiled.
- [#324](alecthomas/voluptuous#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](alecthomas/voluptuous#328):
  Modify `__lt__` in Marker class to allow comparison with non Marker objects, such as str and int.
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