Skip to content
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

documentation/python: make links to literal ellipses as well #214

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions documentation/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,10 +1191,14 @@ def extract_annotation(state: State, referrer_path: List[str], annotation) -> Tu
elif isinstance(annotation, typing.TypeVar):
return annotation.__name__, annotation.__name__

# Ellipsis -- print a literal `...`
# TODO: any chance to link this to python official docs?
# Ellipsis -- print a literal `...`, link to Ellipsis in python docs
elif annotation is ...:
return '...', '...'
# TODO m.sphinx needs to have a special case to extract `...` from
# python.inv (which is a `std.term`, alongside generic stuff like
# "class", "py" etc. which we DON'T want to link to) and convert it to
# a link to Ellipsis, or alternatively pass Ellipsis here but make it
# display as a literal ...
return '...', make_name_link(state, referrer_path, 'Ellipsis')

# If the annotation is from the typing module, it ... gets complicated. It
# could be a "bracketed" type, in which case we want to recurse to its
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def type_string(a: 'Foo'):
def type_nested(a: Tuple[Foo, List[Enum], Any]):
"""A function with nested type annotation"""

def type_nested_ellipsis(a: Tuple[int, ...]):
"""A function with a variadic tuple annotation"""

def type_string_nested(a: 'Tuple[Foo, List[Enum], Any]'):
"""A function with string nested type annotation"""

Expand Down