Repository: keleshev/schema

Issue:
Inconsistent return types for validate: type(schema) or type(data)?
I've noted a small inconsistency when validating with iterable and dict schemas:

```python
        if flavor == ITERABLE:
            data = Schema(type(s), error=e).validate(data)
            return type(s)(Or(*s, error=e).validate(d) for d in data)
        if flavor == DICT:
            data = Schema(dict, error=e).validate(data)
            new = type(data)()  # new - is a dict of the validated values
            ...
            return new
```

Briefly, when validating with iterable schemas the return type is that of the schema, when validating with dict schemas it's that of the input.

Personally I think that it's more flexible to have the return type match the one of the input.

Ideas, preferences?

Discussion:

Patch:
diff --git a/schema.py b/schema.py
index b8abee4..f4f5460 100644
--- a/schema.py
+++ b/schema.py
@@ -109,7 +109,7 @@ class Schema(object):
         if flavor == ITERABLE:
             data = Schema(type(s), error=e).validate(data)
             o = Or(*s, error=e)
-            return type(s)(o.validate(d) for d in data)
+            return type(data)(o.validate(d) for d in data)
         if flavor == DICT:
             data = Schema(dict, error=e).validate(data)
             new = type(data)()  # new - is a dict of the validated values


Test patch:
diff --git a/test_schema.py b/test_schema.py
index 967dec0..e124fc9 100644
--- a/test_schema.py
+++ b/test_schema.py
@@ -408,3 +408,10 @@ def test_exception_handling_with_bad_validators():
         except SchemaError as e:
             assert "TypeError" in e.args[0]
             raise
+
+
+def test_issue_83_iterable_validation_return_type():
+    TestSetType = type("TestSetType", (set,), dict())
+    data = TestSetType(["test", "strings"])
+    s = Schema(set([str]))
+    assert isinstance(s.validate(data), TestSetType)