Skip to content

Conversation

splbio
Copy link
Contributor

@splbio splbio commented Oct 20, 2020

Doctest needs to Ignore objects that inspect.unwrap throws ValueError due to "infinite" nesting.

This case is relatively commonly reproduced by importing unittest.mock.call into a module's namespace.

The following code produces a module that will crash doctest:

from unittest.mock import call

This is due to the call to unwrap throwing an uncaught ValueError.

For this case we can simply ignore the function and not attempt to extract docstring from this function.

This diff is intentionally done as a branch with two commits to provide failing test case and then a fix to show the problem is contained.

Future thoughts:

  1. Should catching this be optional defaulting to true, but allowing for folks to rethrow the exception to insist on truly clean code?
  2. Should we break out _find() into more sub functions so that we can more easily derive our own versions for each sub function that _find does making it easier to fix future issues?
  3. Should we include a way to denylist by id some objects so that future objects that cause problems with doctest can be passed in to ignore?

Note: This branch diff will need to be pulled up into 3.9 and master as the bug exists in those branches as well.

https://bugs.python.org/issue35753

Summary:

Ignore objects that inspect.unwrap throws due to
too many wrappers.  This is a very rare case, however
it can easily be surfaced when a module under doctest
imports unitest.mock.call into its namespace.
@splbio splbio force-pushed the fix-issue-35753-doctest-unwrap-3-8 branch from cbe1707 to 3b6a384 Compare October 26, 2020 03:12
@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Dec 16, 2020
@splbio
Copy link
Contributor Author

splbio commented Dec 16, 2020

will wait for #22981 to be accepted.

@splbio splbio closed this Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants