Fix formatting type annotations for tuples with more than two arguments #5167
+16
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently in Python 3.6, Sphinx formats this function:
in the following way (which can be seen in the Travis log for the first commit in this PR):
This is because the tuple gets treated as a function, and the last
int
is treated like a return value.This affects only
format_annotation_old
function.format_annotation_new
which is used for Python 3.7 is not affected.This pull request fixes this bug, and adds a test.
There is a
hasattr(annotation, '__tuple_params__')
clause below in that function. I am not sure for which Python version it is because all versions I tested (2.7, 3.5, 3.6, 3.7) do not have this attribute. Maybe it is for 3.4? Anyway I added an opposite condition (not hasattr
) to be on the safe side.