Fix type name of FieldInfo namedtuple (#9124)

* Fix type name of `FieldInfo` namedtuple

* Add test
This commit is contained in:
Viicos 2023-10-04 19:03:10 +02:00 committed by GitHub
parent 605cc4f736
commit d32346bae5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -7,7 +7,7 @@ Usage: `get_field_info(model)` returns a `FieldInfo` instance.
""" """
from collections import namedtuple from collections import namedtuple
FieldInfo = namedtuple('FieldResult', [ FieldInfo = namedtuple('FieldInfo', [
'pk', # Model field instance 'pk', # Model field instance
'fields', # Dict of field name -> model field instance 'fields', # Dict of field name -> model field instance
'forward_relations', # Dict of field name -> RelationInfo 'forward_relations', # Dict of field name -> RelationInfo

View File

@ -9,6 +9,7 @@ from rest_framework.serializers import ModelSerializer
from rest_framework.utils import json from rest_framework.utils import json
from rest_framework.utils.breadcrumbs import get_breadcrumbs from rest_framework.utils.breadcrumbs import get_breadcrumbs
from rest_framework.utils.formatting import lazy_format from rest_framework.utils.formatting import lazy_format
from rest_framework.utils.model_meta import FieldInfo, RelationInfo
from rest_framework.utils.urls import remove_query_param, replace_query_param from rest_framework.utils.urls import remove_query_param, replace_query_param
from rest_framework.views import APIView from rest_framework.views import APIView
from rest_framework.viewsets import ModelViewSet from rest_framework.viewsets import ModelViewSet
@ -267,3 +268,9 @@ class LazyFormatTests(TestCase):
assert message.format.call_count == 1 assert message.format.call_count == 1
str(formatted) str(formatted)
assert message.format.call_count == 1 assert message.format.call_count == 1
class ModelMetaNamedTupleNames(TestCase):
def test_named_tuple_names(self):
assert FieldInfo.__name__ == 'FieldInfo'
assert RelationInfo.__name__ == 'RelationInfo'