diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 244d670b81..5780c8e311 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,6 +18,7 @@ repos: - id: flake8 additional_dependencies: - flake8-tidy-imports + - flake8-bugbear - repo: https://github.com/adamchainz/blacken-docs rev: 1.20.0 hooks: diff --git a/rest_framework/filters.py b/rest_framework/filters.py index 3f4730da84..010c87374f 100644 --- a/rest_framework/filters.py +++ b/rest_framework/filters.py @@ -249,7 +249,9 @@ def get_default_ordering(self, view): return (ordering,) return ordering - def get_default_valid_fields(self, queryset, view, context={}): + def get_default_valid_fields(self, queryset, view, context=None): + if context is None: + context = {} # If `ordering_fields` is not specified, then we determine a default # based on the serializer class, if one exists on the view. if hasattr(view, 'get_serializer_class'): @@ -286,7 +288,9 @@ def get_default_valid_fields(self, queryset, view, context={}): ) ] - def get_valid_fields(self, queryset, view, context={}): + def get_valid_fields(self, queryset, view, context=None): + if context is None: + context = {} valid_fields = getattr(view, 'ordering_fields', self.ordering_fields) if valid_fields is None: diff --git a/setup.cfg b/setup.cfg index aebdf53629..6553bfcd5e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,4 @@ [flake8] -ignore = E501,W503,W504 +extend-ignore = E501,W503,W504,B +extend-select = B006 banned-modules = json = use from rest_framework.utils import json!