We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1088b22 commit 64d53caCopy full SHA for 64d53ca
1 file changed
tests/models.py
@@ -9,21 +9,16 @@
9
10
11
class ComplexEncoder(json.JSONEncoder):
12
- def default(self, obj):
13
- if isinstance(obj, complex):
14
- return {
15
- '__complex__': True,
16
- 'real': obj.real,
17
- 'imag': obj.imag,
18
- }
19
-
20
- return json.JSONEncoder.default(self, obj)
+ def default(self, o):
+ return {
+ '__complex__': True,
+ 'real': o.real,
+ 'imag': o.imag,
+ }
21
22
23
def as_complex(dct):
24
- if '__complex__' in dct:
25
- return complex(dct['real'], dct['imag'])
26
- return dct
+ return complex(dct['real'], dct['imag'])
27
28
29
class GenericForeignKeyObj(models.Model):
0 commit comments