transformers - ✅(Solved) Fix ValueError in zero_shot_object_detection.md doctest on Python 3.13 [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
huggingface/transformers#45657Fetched 2026-04-28 06:24:50
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Participants
Timeline (top)
cross-referenced ×1

Error Message

(py313_env) ankitahlawat@AnkitAhlawats-MacBook-Pro transformers % pytest . ================================================================================================ test session starts ================================================================================================= platform darwin -- Python 3.13.7, pytest-8.4.2, pluggy-1.6.0 Test order randomisation NOT enabled. Enable with --random-order or --random-order-bucket=<bucket_type> rootdir: /Users/ankitahlawat/Desktop/AnkitAhlawat/opensource_contribution/transformers configfile: pyproject.toml plugins: anyio-4.12.1, xdist-3.8.0, random-order-1.2.0, timeout-2.4.0, order-1.4.0, rerunfailures-15.1, asyncio-1.3.0, env-1.2.0, rich-0.2.0 asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=function, asyncio_default_test_loop_scope=function collected 130641 items / 1 error

======================================================================================================= ERRORS ======================================================================================================= ________________________________________________________________________ ERROR collecting docs/source/en/tasks/zero_shot_object_detection.md _________________________________________________________________________ /opt/homebrew/Cellar/[email protected]/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/doctest.py:703: in get_doctest return DocTest(self.get_examples(string, name), globs, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ /opt/homebrew/Cellar/[email protected]/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/doctest.py:717: in get_examples return [x for x in self.parse(string, name) ^^^^^^^^^^^^^^^^^^^^^^^^ src/transformers/testing_utils.py:2883: in parse return super().parse(string, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ /opt/homebrew/Cellar/[email protected]/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/doctest.py:679: in parse self._parse_example(m, name, lineno) /opt/homebrew/Cellar/[email protected]/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/doctest.py:737: in _parse_example self._check_prompt_blank(source_lines, indent, name, lineno) /opt/homebrew/Cellar/[email protected]/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/doctest.py:821: in _check_prompt_blank raise ValueError('line %r of the docstring for %s ' E ValueError: line 172 of the docstring for zero_shot_object_detection.md lacks blank after ...: '...)[0]'

PR fix notes

PR #45669: zero_shot_object_detection ValueError fix for python 3.13

Description (problem / solution / changelog)

What does this PR do?

Python 3.13's doctest parser enforces stricter syntax validation. The closing )[0] is placed on a ... continuation line, which is no longer accepted so this PR fixes the malformed doctest by splitting the indexing into a separate statement, making it compatible with Python 3.13's parser while keeping the same behavior.

Fixes #45657

Code Agent Policy

  • I confirm that this is not a pure code agent PR.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline, Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the documentation guidelines, and here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Documentation: @stevhliu

Changed files

  • docs/source/en/tasks/zero_shot_object_detection.md (modified, +1/-1)

Code Example

(py313_env) ankitahlawat@AnkitAhlawats-MacBook-Pro transformers % pytest .
================================================================================================ test session starts =================================================================================================
platform darwin -- Python 3.13.7, pytest-8.4.2, pluggy-1.6.0
Test order randomisation NOT enabled. Enable with --random-order or --random-order-bucket=<bucket_type>
rootdir: /Users/ankitahlawat/Desktop/AnkitAhlawat/opensource_contribution/transformers
configfile: pyproject.toml
plugins: anyio-4.12.1, xdist-3.8.0, random-order-1.2.0, timeout-2.4.0, order-1.4.0, rerunfailures-15.1, asyncio-1.3.0, env-1.2.0, rich-0.2.0
asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=function, asyncio_default_test_loop_scope=function
collected 130641 items / 1 error

======================================================================================================= ERRORS =======================================================================================================
________________________________________________________________________ ERROR collecting docs/source/en/tasks/zero_shot_object_detection.md _________________________________________________________________________
/opt/homebrew/Cellar/python@3.13/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/doctest.py:703: in get_doctest
    return DocTest(self.get_examples(string, name), globs,
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/opt/homebrew/Cellar/python@3.13/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/doctest.py:717: in get_examples
    return [x for x in self.parse(string, name)
                       ^^^^^^^^^^^^^^^^^^^^^^^^
src/transformers/testing_utils.py:2883: in parse
    return super().parse(string, name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
/opt/homebrew/Cellar/python@3.13/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/doctest.py:679: in parse
    self._parse_example(m, name, lineno)
/opt/homebrew/Cellar/python@3.13/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/doctest.py:737: in _parse_example
    self._check_prompt_blank(source_lines, indent, name, lineno)
/opt/homebrew/Cellar/python@3.13/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/doctest.py:821: in _check_prompt_blank
    raise ValueError('line %r of the docstring for %s '
E   ValueError: line 172 of the docstring for zero_shot_object_detection.md lacks blank after ...: '...)[0]'

---

@@ -169,7 +169,7 @@ boxes have the correct coordinates relative to the original image:

 >>> results = processor.post_process_grounded_object_detection(
 ...    outputs, threshold=0.50, target_sizes=[(image.height, image.width)], text_labels=text_labels,
-...)[0]
+... )[0]

 >>> draw = ImageDraw.Draw(image)
RAW_BUFFERClick to expand / collapse

While running the test suite on Python 3.13.7, pytest fails to collect tests due to a malformed doctest in docs/source/en/tasks/zero_shot_object_detection.md. Environment:

Python: 3.13.7 Platform: macOS (darwin) transformers: main branch

Error: ValueError: line 172 of the docstring for zero_shot_object_detection.md lacks blank after ...: '...)[0]'

(py313_env) ankitahlawat@AnkitAhlawats-MacBook-Pro transformers % pytest .
================================================================================================ test session starts =================================================================================================
platform darwin -- Python 3.13.7, pytest-8.4.2, pluggy-1.6.0
Test order randomisation NOT enabled. Enable with --random-order or --random-order-bucket=<bucket_type>
rootdir: /Users/ankitahlawat/Desktop/AnkitAhlawat/opensource_contribution/transformers
configfile: pyproject.toml
plugins: anyio-4.12.1, xdist-3.8.0, random-order-1.2.0, timeout-2.4.0, order-1.4.0, rerunfailures-15.1, asyncio-1.3.0, env-1.2.0, rich-0.2.0
asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=function, asyncio_default_test_loop_scope=function
collected 130641 items / 1 error

======================================================================================================= ERRORS =======================================================================================================
________________________________________________________________________ ERROR collecting docs/source/en/tasks/zero_shot_object_detection.md _________________________________________________________________________
/opt/homebrew/Cellar/[email protected]/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/doctest.py:703: in get_doctest
    return DocTest(self.get_examples(string, name), globs,
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/opt/homebrew/Cellar/[email protected]/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/doctest.py:717: in get_examples
    return [x for x in self.parse(string, name)
                       ^^^^^^^^^^^^^^^^^^^^^^^^
src/transformers/testing_utils.py:2883: in parse
    return super().parse(string, name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
/opt/homebrew/Cellar/[email protected]/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/doctest.py:679: in parse
    self._parse_example(m, name, lineno)
/opt/homebrew/Cellar/[email protected]/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/doctest.py:737: in _parse_example
    self._check_prompt_blank(source_lines, indent, name, lineno)
/opt/homebrew/Cellar/[email protected]/3.13.7/Frameworks/Python.framework/Versions/3.13/lib/python3.13/doctest.py:821: in _check_prompt_blank
    raise ValueError('line %r of the docstring for %s '
E   ValueError: line 172 of the docstring for zero_shot_object_detection.md lacks blank after ...: '...)[0]'

can be fix like

@@ -169,7 +169,7 @@ boxes have the correct coordinates relative to the original image:

 >>> results = processor.post_process_grounded_object_detection(
 ...    outputs, threshold=0.50, target_sizes=[(image.height, image.width)], text_labels=text_labels,
-...)[0]
+... )[0]

 >>> draw = ImageDraw.Draw(image)

extent analysis

TL;DR

The issue can be fixed by adding a blank space after the ellipsis in the docstring of zero_shot_object_detection.md.

Guidance

  • The error message indicates a ValueError due to a malformed doctest in zero_shot_object_detection.md, specifically a missing blank space after an ellipsis.
  • To fix this, add a blank space after the ellipsis in the docstring, as shown in the provided patch.
  • Verify that the test suite runs successfully after applying the fix.
  • The issue is specific to Python 3.13.7 and the transformers library, so ensure that the fix is applied to the correct version and library.

Example

The provided patch shows the correct fix:

@@ -169,7 +169,7 @@ boxes have the correct coordinates relative to the original image:

 >>> results = processor.post_process_grounded_object_detection(
 ...    outputs, threshold=0.50, target_sizes=[(image.height, image.width)], text_labels=text_labels,
-...)[0]
+... )[0]

Notes

The fix is specific to the zero_shot_object_detection.md file and may not apply to other files or versions.

Recommendation

Apply the workaround by adding a blank space after the ellipsis in the docstring, as shown in the provided patch. This should fix the issue and allow the test suite to run successfully.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

transformers - ✅(Solved) Fix ValueError in zero_shot_object_detection.md doctest on Python 3.13 [1 pull requests, 1 participants]