|
8 | 8 |
|
9 | 9 | class SchemaCastersFactory(object): |
10 | 10 |
|
11 | | - DUMMY_CASTER = DummyCaster() |
| 11 | + DUMMY_CASTERS = [ |
| 12 | + SchemaType.STRING, SchemaType.OBJECT, SchemaType.ANY, |
| 13 | + ] |
12 | 14 | PRIMITIVE_CASTERS = { |
13 | | - SchemaType.STRING: DUMMY_CASTER, |
14 | | - SchemaType.INTEGER: PrimitiveCaster(int), |
15 | | - SchemaType.NUMBER: PrimitiveCaster(float), |
16 | | - SchemaType.BOOLEAN: PrimitiveCaster(forcebool), |
17 | | - SchemaType.OBJECT: DUMMY_CASTER, |
18 | | - SchemaType.ANY: DUMMY_CASTER, |
| 15 | + SchemaType.INTEGER: int, |
| 16 | + SchemaType.NUMBER: float, |
| 17 | + SchemaType.BOOLEAN: forcebool, |
19 | 18 | } |
20 | 19 | COMPLEX_CASTERS = { |
21 | 20 | SchemaType.ARRAY: ArrayCaster, |
22 | 21 | } |
23 | 22 |
|
24 | 23 | def create(self, schema): |
25 | | - if schema.type in self.PRIMITIVE_CASTERS: |
26 | | - return self.PRIMITIVE_CASTERS[schema.type] |
| 24 | + if schema.type in self.DUMMY_CASTERS: |
| 25 | + return DummyCaster() |
| 26 | + elif schema.type in self.PRIMITIVE_CASTERS: |
| 27 | + caster_callable = self.PRIMITIVE_CASTERS[schema.type] |
| 28 | + return PrimitiveCaster(schema, caster_callable) |
27 | 29 | elif schema.type in self.COMPLEX_CASTERS: |
28 | 30 | caster_class = self.COMPLEX_CASTERS[schema.type] |
29 | | - return caster_class(schema=schema, casters_factory=self) |
| 31 | + return caster_class(schema, self) |
0 commit comments