Enforce is_valid(raise_exception=False) as a keyword-only argument. (#7952)

* make raise_exception a keyword-only argument

* make raise_exception keyword-only in metaclass
This commit is contained in:
ProstoMaxim 2022-08-10 16:00:30 +03:00 committed by GitHub
parent 35a6d65e22
commit 791d48c690
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -216,7 +216,7 @@ class BaseSerializer(Field):
return self.instance return self.instance
def is_valid(self, raise_exception=False): def is_valid(self, *, raise_exception=False):
assert hasattr(self, 'initial_data'), ( assert hasattr(self, 'initial_data'), (
'Cannot call `.is_valid()` as no `data=` keyword argument was ' 'Cannot call `.is_valid()` as no `data=` keyword argument was '
'passed when instantiating the serializer instance.' 'passed when instantiating the serializer instance.'
@ -735,7 +735,7 @@ class ListSerializer(BaseSerializer):
return self.instance return self.instance
def is_valid(self, raise_exception=False): def is_valid(self, *, raise_exception=False):
# This implementation is the same as the default, # This implementation is the same as the default,
# except that we use lists, rather than dicts, as the empty case. # except that we use lists, rather than dicts, as the empty case.
assert hasattr(self, 'initial_data'), ( assert hasattr(self, 'initial_data'), (