@@ -104,7 +104,8 @@ def get_attribute(instance, attrs):
104
104
# If we raised an Attribute or KeyError here it'd get treated
105
105
# as an omitted field in `Field.get_attribute()`. Instead we
106
106
# raise a ValueError to ensure the exception is not masked.
107
- raise ValueError ('Exception raised in callable attribute "{}"; original exception was: {}' .format (attr , exc ))
107
+ raise ValueError (
108
+ 'Exception raised in callable attribute "{}"; original exception was: {}' .format (attr , exc ))
108
109
109
110
return instance
110
111
@@ -181,6 +182,7 @@ def iter_options(grouped_choices, cutoff=None, cutoff_text=None):
181
182
"""
182
183
Helper function for options and option groups in templates.
183
184
"""
185
+
184
186
class StartOptionGroup :
185
187
start_option_group = True
186
188
end_option_group = False
@@ -366,10 +368,10 @@ def bind(self, field_name, parent):
366
368
# 'source' argument has been used. For example:
367
369
# my_field = serializer.CharField(source='my_field')
368
370
assert self .source != field_name , (
369
- "It is redundant to specify `source='%s'` on field '%s' in "
370
- "serializer '%s', because it is the same as the field name. "
371
- "Remove the `source` keyword argument." %
372
- (field_name , self .__class__ .__name__ , parent .__class__ .__name__ )
371
+ "It is redundant to specify `source='%s'` on field '%s' in "
372
+ "serializer '%s', because it is the same as the field name. "
373
+ "Remove the `source` keyword argument." %
374
+ (field_name , self .__class__ .__name__ , parent .__class__ .__name__ )
373
375
)
374
376
375
377
self .field_name = field_name
@@ -794,7 +796,8 @@ def __init__(self, allow_unicode=False, **kwargs):
794
796
super ().__init__ (** kwargs )
795
797
self .allow_unicode = allow_unicode
796
798
if self .allow_unicode :
797
- validator = RegexValidator (re .compile (r'^[-\w]+\Z' , re .UNICODE ), message = self .error_messages ['invalid_unicode' ])
799
+ validator = RegexValidator (re .compile (r'^[-\w]+\Z' , re .UNICODE ),
800
+ message = self .error_messages ['invalid_unicode' ])
798
801
else :
799
802
validator = RegexValidator (re .compile (r'^[-a-zA-Z0-9_]+$' ), message = self .error_messages ['invalid' ])
800
803
self .validators .append (validator )
@@ -943,7 +946,7 @@ def to_internal_value(self, data):
943
946
944
947
try :
945
948
return float (data )
946
- except (TypeError , ValueError ):
949
+ except (TypeError , ValueError , OverflowError ):
947
950
self .fail ('invalid' )
948
951
949
952
def to_representation (self , value ):
@@ -994,7 +997,7 @@ def __init__(self, max_digits, decimal_places, coerce_to_string=None, max_value=
994
997
if rounding is not None :
995
998
valid_roundings = [v for k , v in vars (decimal ).items () if k .startswith ('ROUND_' )]
996
999
assert rounding in valid_roundings , (
997
- 'Invalid rounding option %s. Valid values for rounding are: %s' % (rounding , valid_roundings ))
1000
+ 'Invalid rounding option %s. Valid values for rounding are: %s' % (rounding , valid_roundings ))
998
1001
self .rounding = rounding
999
1002
1000
1003
def validate_empty_values (self , data ):
@@ -1732,6 +1735,7 @@ def __new__(cls, value):
1732
1735
ret = str .__new__ (cls , value )
1733
1736
ret .is_json_string = True
1734
1737
return ret
1738
+
1735
1739
return JSONString (dictionary [self .field_name ])
1736
1740
return dictionary .get (self .field_name , empty )
1737
1741
@@ -1785,6 +1789,7 @@ class HiddenField(Field):
1785
1789
constraint on a pair of fields, as we need some way to include the date in
1786
1790
the validated data.
1787
1791
"""
1792
+
1788
1793
def __init__ (self , ** kwargs ):
1789
1794
assert 'default' in kwargs , 'default is a required argument.'
1790
1795
kwargs ['write_only' ] = True
@@ -1814,6 +1819,7 @@ class ExampleSerializer(Serializer):
1814
1819
def get_extra_info(self, obj):
1815
1820
return ... # Calculate some data to return.
1816
1821
"""
1822
+
1817
1823
def __init__ (self , method_name = None , ** kwargs ):
1818
1824
self .method_name = method_name
1819
1825
kwargs ['source' ] = '*'
0 commit comments