ipython/ipython

Format complicated type hints better in help

开放

#13,655 创建于 2022年4月26日

 (7 条评论) (0 个反应) (0 位负责人)Python (4,400 个派生)batch import
UIhelp wantedmagics

仓库指标

星标
 (16,095 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

I typed

In [1]: from prompt_toolkit import prompt

In [2]: prompt??

because I wanted to know the default for some argument in that api. It printed the following,

Signature:
prompt(
    message: Union[str, ForwardRef('MagicFormattedText'), List[Union[Tuple[str, str], Tuple[str, str, Callable[[prompt_toolkit.mouse_events.MouseEvent], NoneType]]]], Callable[[], Any], NoneType] = None,
    *,
    history: Optional[prompt_toolkit.history.History] = None,
    editing_mode: Optional[prompt_toolkit.enums.EditingMode] = None,
    refresh_interval: Optional[float] = None,
    vi_mode: Optional[bool] = None,
    lexer: Optional[prompt_toolkit.lexers.base.Lexer] = None,
    completer: Optional[prompt_toolkit.completion.base.Completer] = None,
    complete_in_thread: Optional[bool] = None,
    is_password: Optional[bool] = None,
    key_bindings: Optional[prompt_toolkit.key_binding.key_bindings.KeyBindingsBase] = None,
    bottom_toolbar: Union[str, ForwardRef('MagicFormattedText'), List[Union[Tuple[str, str], Tuple[str, str, Callable[[prompt_toolkit.mouse_events.MouseEvent], NoneType]]]], Callable[[], Any], NoneType] = None,
    style: Optional[prompt_toolkit.styles.base.BaseStyle] = None,
    color_depth: Optional[prompt_toolkit.output.color_depth.ColorDepth] = None,
    cursor: Union[prompt_toolkit.cursor_shapes.CursorShape, prompt_toolkit.cursor_shapes.CursorShapeConfig, NoneType] = None,
    include_default_pygments_style: Union[prompt_toolkit.filters.base.Filter, bool, NoneType] = None,
    style_transformation: Optional[prompt_toolkit.styles.style_transformation.StyleTransformation] = None,
    swap_light_and_dark_colors: Union[prompt_toolkit.filters.base.Filter, bool, NoneType] = None,
    rprompt: Union[str, ForwardRef('MagicFormattedText'), List[Union[Tuple[str, str], Tuple[str, str, Callable[[prompt_toolkit.mouse_events.MouseEvent], NoneType]]]], Callable[[], Any], NoneType] = None,
    multiline: Union[prompt_toolkit.filters.base.Filter, bool, NoneType] = None,
    prompt_continuation: Union[str, ForwardRef('MagicFormattedText'), List[Union[Tuple[str, str], Tuple[str, str, Callable[[prompt_toolkit.mouse_events.MouseEvent], NoneType]]]], Callable[[int, int, int], Union[str, ForwardRef('MagicFormattedText'), List[Union[Tuple[str, str], Tuple[str, str, Callable[[prompt_toolkit.mouse_events.MouseEvent], NoneType]]]], Callable[[], Any], NoneType]], NoneType] = None,
    wrap_lines: Union[prompt_toolkit.filters.base.Filter, bool, NoneType] = None,
    enable_history_search: Union[prompt_toolkit.filters.base.Filter, bool, NoneType] = None,
    search_ignore_case: Union[prompt_toolkit.filters.base.Filter, bool, NoneType] = None,
    complete_while_typing: Union[prompt_toolkit.filters.base.Filter, bool, NoneType] = None,
    validate_while_typing: Union[prompt_toolkit.filters.base.Filter, bool, NoneType] = None,
    complete_style: Optional[prompt_toolkit.shortcuts.prompt.CompleteStyle] = None,
    auto_suggest: Optional[prompt_toolkit.auto_suggest.AutoSuggest] = None,
    validator: Optional[prompt_toolkit.validation.Validator] = None,
    clipboard: Optional[prompt_toolkit.clipboard.base.Clipboard] = None,
    mouse_support: Union[prompt_toolkit.filters.base.Filter, bool, NoneType] = None,
    input_processors: Optional[List[prompt_toolkit.layout.processors.Processor]] = None,
    placeholder: Union[str, ForwardRef('MagicFormattedText'), List[Union[Tuple[str, str], Tuple[str, str, Callable[[prompt_toolkit.mouse_events.MouseEvent], NoneType]]]], Callable[[], Any], NoneType] = None,
    reserve_space_for_menu: Optional[int] = None,
    enable_system_prompt: Union[prompt_toolkit.filters.base.Filter, bool, NoneType] = None,
    enable_suspend: Union[prompt_toolkit.filters.base.Filter, bool, NoneType] = None,
    enable_open_in_editor: Union[prompt_toolkit.filters.base.Filter, bool, NoneType] = None,
    tempfile_suffix: Union[str, Callable[[], str], NoneType] = None,
    tempfile: Union[str, Callable[[], str], NoneType] = None,
    default: str = '',
    accept_default: bool = False,
    pre_run: Optional[Callable[[], NoneType]] = None,
) -> str
Docstring:
Display the prompt.

which I found rather unhelpful. For one the annotation of the argument I was interested in doesn't fit in a single line in the terminal. I wonder if there is a way to make less prominent long complicated annotations. This could be done by changing the color in which their are displayed, imposing a maximum length for the type hint or having an option is to hide annotations altogether from help. Another possibility would be to try to keep the type aliases as in the original source code rather than resolving them. Not sure how easy that is.

贡献者指南