From 492529006d531b828ae1ca9232e95a5fbb050b32 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Mon, 18 Mar 2024 22:14:05 +0000 Subject: [PATCH] Make inflection compat layer consistent with the others Co-authored-by: T. Franzel <13507857+tfranzel@users.noreply.github.com> --- rest_framework/compat.py | 7 ++----- rest_framework/schemas/openapi.py | 5 +++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 96349aca0..afc06b6cb 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -48,12 +48,9 @@ except ImportError: # inflection is optional try: - from inflection import pluralize + import inflection except ImportError: - def pluralize(text): - if not text.endswith('s'): - text += "s" - return text + inflection = None # requests is optional diff --git a/rest_framework/schemas/openapi.py b/rest_framework/schemas/openapi.py index 5a1f64b89..38031e646 100644 --- a/rest_framework/schemas/openapi.py +++ b/rest_framework/schemas/openapi.py @@ -14,7 +14,7 @@ from django.utils.encoding import force_str from rest_framework import ( RemovedInDRF315Warning, exceptions, renderers, serializers ) -from rest_framework.compat import pluralize, uritemplate +from rest_framework.compat import inflection, uritemplate from rest_framework.fields import _UnvalidatedField, empty from rest_framework.settings import api_settings @@ -247,7 +247,8 @@ class AutoSchema(ViewInspector): name = name[:-len(action)] if action == 'list': - name = pluralize(name) + assert inflection, '`inflection` must be installed for OpenAPI schema support.' + name = inflection.pluralize(name) return name