which surprises user and it even not mentioned in documentation.
Could we change this behavior? I know that we don’t have a perfect solution, but returning None in this case is less bad than empty list [], because it is easier to annotate type.
If returns None, we can annotate type as str | None.
If returns [], Python doesn’t have an exact type for empty list, and django-stubs has to annotate as str | list[object] which is quite broader than the actual value (empty list).
The issue has been reported in Django issue tracker, but I’m advised to post here to hear more opinions.
The issue is the bottom except in MultiValueDict.__getitem__:
What do we do when the list is empty?
Arguably, a correct answer might be to raise a MultiValueDictKeyError as we do above… — after all there is no single item that can be returned — in contrast to getlist(), which would correctly return the empty list.