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

Better old-style class support #279

Merged
merged 2 commits into from
Apr 18, 2017
Merged

Conversation

ngaya-ll
Copy link
Contributor

@ngaya-ll ngaya-ll commented Apr 14, 2017

Treat old-style classes like types when validating. Prior to this patch, old-style classes in Python 2 would be treated like callables, leading to unexpected behavior.

>>> from plistlib import Data  # old-style class from standard library
>>> from voluptuous import Schema
>>> schema = Schema(Data)
>>> schema(Data('abc'))
Data(Data('abc'))
>>> schema('abc')
Data('abc')

With this patch, old-style classes are treated the same as types. This leads to better consistency between new-style and old-style classes.

>>> from plistlib import Data  # old-style class from standard library
>>> from voluptuous import Schema
>>> schema = Schema(Data)
>>> schema(Data('abc'))
Data('abc')
>>> schema('abc')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "voluptuous/schema_builder.py", line 225, in __call__
    raise er.MultipleInvalid([e])
voluptuous.error.MultipleInvalid: expected Data

@coveralls
Copy link

coveralls commented Apr 14, 2017

Coverage Status

Coverage remained the same at 95.652% when pulling f47615a on ngaya-ll:master into 2a690a8 on alecthomas:master.

@coveralls
Copy link

coveralls commented Apr 14, 2017

Coverage Status

Coverage remained the same at 95.652% when pulling a404944 on ngaya-ll:master into 2a690a8 on alecthomas:master.

Copy link
Collaborator

@tusharmakkar08 tusharmakkar08 left a comment

Choose a reason for hiding this comment

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

This PR looks fine to me. Please update CHANGELOG.md mentioning the changes.

@coveralls
Copy link

coveralls commented Apr 17, 2017

Coverage Status

Coverage remained the same at 95.652% when pulling 25da46e on ngaya-ll:master into 2a690a8 on alecthomas:master.

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