Whole file

keleshev/schema

The author described this change as Fix reliance on `__name__` of callables. It counts as a record because the check below fails on the code as it stood at 29286c1f9 and passes on c80e72f59, with nothing else changed between the two runs.

Fix saved2015-09-26
Sharing licenceMIT · LICENSE-MIT
Change size+8 2

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

Fix reliance on `__name__` of callables

The change

7070 except SchemaError as x:
7171 raise SchemaError([None] + x.autos, [self._error] + x.errors)
7272 except BaseException as x:
73- f = self._callable.__name__
73+ f = callable_str(self._callable)
7474 raise SchemaError('%s(%r) raised %r' % (f, data, x), self._error)
7575
7676
176176 raise SchemaError('%r.validate(%r) raised %r' % (s, data, x),
177177 self._error)
178178 if flavor == CALLABLE:
179- f = s.__name__
179+ f = callable_str(s)
180180 try:
181181 if s(data):
182182 return data
211211 '"%r" is too complex.' % (self._schema,))
212212 self.default = default
213213 self.key = self._schema
214+
215+
216+def callable_str(callable_):
217+ if hasattr(callable_, '__name__'):
218+ return callable_.__name__
219+ return str(callable_)
214220

The check that tells the two apart

failpass·test_schema.py::test_issue_56_cant_rely_on_callables_to_have_name

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 it29286c1f9cce20cf70f2b15d9247f2ca6ef1d6c9
Broken version dated2015-09-26
Moduleschema
Units changedSchema, Use
Fingerprint1e0b9819a8afabc4
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