-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Remove mypy overrides for test_environment #14088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Remove mypy overrides for test_environment #14088
Conversation
| toctree[0][0], | ||
| [compact_paragraph, reference, 'Welcome to Sphinx Tests’s documentation!'], | ||
| toctree_0_0, | ||
| [compact_paragraph, reference, "Welcome to Sphinx Tests's documentation!"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
| assert_node(toctree_0_0[0], reference, anchorname='') | ||
|
|
||
| toctree_0_1 = toctree_0[1] | ||
| assert isinstance(toctree_0_1, Element) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be worth extracting this to a helper. something like-
def extract_element(node: Node, *indices: int) -> Node:
"""
Walk down a docutils node tree by repeatedly indexing children.
Example:
extract_element(doc, 0, 2, 1) == doc[0][2][1]
"""
current: Node = node
for depth, i in enumerate(indices):
assert isinstance(current, Element), (
f"Expected Element at depth {depth} before indexing with [{i}], "
f"got {type(current).__name__!r}"
)
try:
current = current[i]
except IndexError as e:
raise AssertionError(
f"Index {i} out of range at depth {depth} for "
f"{type(current).__name__!r}"
) from e
return currentthere's a lot of tests that could use something like this to resolve type issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danieleades Maybe move to tests/utils.py? Either this PR or a new one would be fine.
Edit: lost context here, thought this was one of your PRs. Would you mind making a PR to add the function?
A
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the first PR that would use this method, so makes as much sense to add it here as anywhere?
sticking in tests/utils makes sense.
failing that, i'm happy to spin up a separate PR to add this utility. I'll see what @adamtheturtle wants to do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's lots of use of the doctree_* pattern already from recent PRs.
A
No description provided.