Skip to content

Return no match for empty supported media types - #56

Closed
ice-pring wants to merge 1 commit into
falconry:masterfrom
ice-pring:fix/empty-supported-media-types
Closed

ice-pring wants to merge 1 commit into
falconry:masterfrom
ice-pring:fix/empty-supported-media-types

Conversation

@ice-pring

Copy link
Copy Markdown

best_match([], 'application/json') raises IndexError when it indexes the last weighted match. Empty tuples and exhausted iterators fail the same way.

Return the usual empty-string result when there are no supported candidates. The check runs after iterating the candidates, so it also handles empty generators. Header parsing still validates malformed media ranges.

Added a case to the shared JSON test data and tests for empty iterables, a nonempty generator, and an invalid header with no candidates. The docstring now describes the no-match return value.

Validation:

  • The added regression cases produce four errors before the fix and pass afterward.
  • python mimeparse_test.py passes.
  • Tox py312 and py314 each pass all 7 test methods on CPython 3.12.14 and 3.14.5.
  • Tox flake8 and git diff --check pass.

@vytas7

vytas7 commented Oct 23, 2026

Copy link
Copy Markdown
Member

Given that you submitted many AI-generated PRs in different repositories, I doubt you have a real use case for this behaviour. We haven't heard from any users about this.

FWIW, the Falcon web framework's reimplementation already works according to your expectation:

>>> from falcon import mediatypes
>>> mediatypes.best_match([], 'some/thing')
''

So I'm going to leave mimeparse as is for now.

@vytas7 vytas7 closed this Oct 23, 2026
@ice-pring

Copy link
Copy Markdown
Author

Thank you for reviewing this and explaining your reasoning. For context, I was testing whether AI could autonomously make useful contributions to open-source projects. I had not established a concrete real-world use case for this change before submitting it.

My intention was to contribute something useful, and I'm sorry for adding to your review workload. I appreciate your time and understand your decision to leave mimeparse as it is. I won't pursue this change further.

@vytas7

vytas7 commented Oct 23, 2026

Copy link
Copy Markdown
Member

Thanks for the explanation.

Pull requests by completely autonomous agents usually cause more harm than good, so try to avoid that.

It is not that the code itself is bad -- LLMs have now reached the point where the code is actually pretty good, or at least (almost) good enough for many projects. However, consider the fact that many maintainers (myself included) haven't been living under a rock either. So if something is deemed to be suitable for an autonomous agent, the maintainers can prompt it themselves, too.

Furthermore, many projects used to have easy issues which served as gentle introduction for new contributors. Using any kind of LLMs on such issues simply defeats the purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants