Skip to content

Is _unset check in ValidationError fails if custom-type has overriden __eq__() method (ie: pandas.DataFrame) #164

@ankostis

Description

@ankostis

I use a custom schema that accepts as sub-trees pandas.DataFrame and pandas.Series instances, classes that have overridden the eq() method.

In case a ValidationError involves such an object, the generated exception is thereafter unusable, since the following check within it unicode() method fails:

 if _unset in ( self.validator, self.validator_value, self.instance, self.schema, ): 

The reason for this is that _unset == self.instance (what the compiler generates for XX in YY expressions) returns multiple boolean values when the self.instance is a pandas.DataFrame.

Since _unset is a sentinel instance, i believe that a more proper approach would be to use the is operator instead, which it cannot be overridden.

The following code snippet would suffice:

if any(m is _unset for m in ( self.validator, self.validator_value, self.instance, self.schema )): 

I would be glad to provide such a patch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions