Whole file

keleshev/schema

The author described this change as fix: Schema can be inherited (#127). It counts as a record because the check below fails on the code as it stood at bca292f3b and passes on 9c6d0826e, with nothing else changed between the two runs.

Fix saved2017-01-17
Sharing licenceMIT · LICENSE-MIT
Change size+7 4

What the code was meant to do, written into the code itself as a save note

fix: Schema can be inherited (#127)

The change

6666 """
6767 def __init__(self, *args, **kw):
6868 self._args = args
69- assert list(kw) in (['error'], [])
69+ assert sorted(list(kw)) in (['error', 'schema'], ['error'], [])
7070 self._error = kw.get('error')
71+ # You can pass your inherited Schema class.
72+ self._schema = kw.get('schema', Schema)
7173
7274 def __repr__(self):
7375 return '%s(%s)' % (self.__class__.__name__,
8082 :param data: to be validated with sub defined schemas.
8183 :return: returns validated data
8284 """
83- for s in [Schema(s, error=self._error) for s in self._args]:
85+ for s in [self._schema(s, error=self._error) for s in self._args]:
8486 data = s.validate(data)
8587 return data
8688
9698 :return: return validated data if not validation
9799 """
98100 x = SchemaError([], [])
99- for s in [Schema(s, error=self._error) for s in self._args]:
101+ for s in [self._schema(s, error=self._error) for s in self._args]:
100102 try:
101103 return s.validate(data)
102104 except SchemaError as _x:
216218 return _priority(s)
217219
218220 def validate(self, data):
221+ Schema = self.__class__
219222 s = self._schema
220223 e = self._error
221224 flavor = _priority(s)
222225 if flavor == ITERABLE:
223226 data = Schema(type(s), error=e).validate(data)
224- o = Or(*s, error=e)
227+ o = Or(*s, error=e, schema=Schema)
225228 return type(data)(o.validate(d) for d in data)
226229 if flavor == DICT:
227230 data = Schema(dict, error=e).validate(data)

The check that tells the two apart

failpass·test_schema.py::test_inheritance

Check file test_schema.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itbca292f3b80daf83186098b6cb0cf2f03f822765
Broken version dated2016-12-15
Moduleschema
Units changedAnd, Or, Schema
Fingerprint328e707d883e8c30
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in keleshev/schema