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.
Projectkeleshev/schema
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
| 70 | 70 | except SchemaError as x: | |
| 71 | 71 | raise SchemaError([None] + x.autos, [self._error] + x.errors) | |
| 72 | 72 | except BaseException as x: | |
| 73 | - | f = self._callable.__name__ | |
| 73 | + | f = callable_str(self._callable) | |
| 74 | 74 | raise SchemaError('%s(%r) raised %r' % (f, data, x), self._error) | |
| 75 | 75 | ||
| 76 | 76 | ||
| ⋯ | |||
| 176 | 176 | raise SchemaError('%r.validate(%r) raised %r' % (s, data, x), | |
| 177 | 177 | self._error) | |
| 178 | 178 | if flavor == CALLABLE: | |
| 179 | - | f = s.__name__ | |
| 179 | + | f = callable_str(s) | |
| 180 | 180 | try: | |
| 181 | 181 | if s(data): | |
| 182 | 182 | return data | |
| ⋯ | |||
| 211 | 211 | '"%r" is too complex.' % (self._schema,)) | |
| 212 | 212 | self.default = default | |
| 213 | 213 | self.key = self._schema | |
| 214 | + | ||
| 215 | + | ||
| 216 | + | def callable_str(callable_): | |
| 217 | + | if hasattr(callable_, '__name__'): | |
| 218 | + | return callable_.__name__ | |
| 219 | + | return str(callable_) | |
| 214 | 220 | ||
The check that tells the two apart
fail→pass·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
- 2026-06-15Fix custom error on a key schema being lost for wrong keys
- 2026-06-13Fix TypeError when building the key error message for a tuple key
- 2025-02-27fix: JSON Schema missing title in subschemas
- 2017-01-17fix: Schema can be inherited (#127)
- 2016-02-16add strict flag in Schema class to skip wrong key validation without wildcard
- 2014-02-03Handle wrong keys better. Fixes #3 and #15