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

help(): Display complex signatures in multiple lines #112139

Closed
JelleZijlstra opened this issue Nov 16, 2023 · 1 comment
Closed

help(): Display complex signatures in multiple lines #112139

JelleZijlstra opened this issue Nov 16, 2023 · 1 comment
Labels
3.13 new features, bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@JelleZijlstra
Copy link
Member

JelleZijlstra commented Nov 16, 2023

Feature or enhancement

Proposal:

Here's the help() output for a reasonably complex typed method (link):

Help on function __init__ in module pyanalyze.name_check_visitor:

__init__(self, filename: str, contents: str, tree: ast.Module, *, settings: Optional[Mapping[pyanalyze.error_code.ErrorCode, bool]] = None, fail_after_first: bool = False, verbosity: int = 50, unused_finder: Optional[pyanalyze.find_unused.UnusedObjectFinder] = None, module: Optional[module] = None, attribute_checker: Optional[pyanalyze.name_check_visitor.ClassAttributeChecker] = None, collector: Optional[pyanalyze.name_check_visitor.CallSiteCollector] = None, annotate: bool = False, add_ignores: bool = False, checker: pyanalyze.checker.Checker, is_code_only: bool = False) -> None
    Constructor.
    
    filename: name of the file to run on (to show in error messages)
    contents: code that the visitor is run on
    fail_after_first: whether to throw an error after the first problem is detected
    verbosity: controls how much logging is emitted

It would be much easier to read if each parameter was on its own line, something like this:

Help on function __init__ in module pyanalyze.name_check_visitor:

__init__(
    self,
    filename: str,
    contents: str,
    tree: ast.Module,
    *,
    settings: Optional[Mapping[pyanalyze.error_code.ErrorCode, bool]] = None,
    fail_after_first: bool = False,
    verbosity: int = 50,
    unused_finder: Optional[pyanalyze.find_unused.UnusedObjectFinder] = None,
    module: Optional[module] = None,
    attribute_checker: Optional[pyanalyze.name_check_visitor.ClassAttributeChecker] = None,
    collector: Optional[pyanalyze.name_check_visitor.CallSiteCollector] = None,
    annotate: bool = False,
    add_ignores: bool = False,
    checker: pyanalyze.checker.Checker,
    is_code_only: bool = False,
) -> None
    Constructor.
    
    filename: name of the file to run on (to show in error messages)
    contents: code that the visitor is run on
    fail_after_first: whether to throw an error after the first problem is detected
    verbosity: controls how much logging is emitted

help() should switch to this output format only for reasonably complex signatures, perhaps if the signature line would otherwise be >80 characters.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

@JelleZijlstra JelleZijlstra added type-feature A feature request or enhancement stdlib Python modules in the Lib dir 3.13 new features, bugs and security fixes labels Nov 16, 2023
@sobolevn
Copy link
Member

It is quite easy to do:
Снимок экрана 2023-11-16 в 10 19 56

I modified __str__ to be def __str__(self, *, pretty=False): and then called it directly from pydoc.

I've also changed how we render the annotation: rendered = '(\n {}\n)'.format(',\n '.join(result)) in case of pretty

I guess that __str__ with custom params might be unusual, however pydecimal does the same.

sobolevn added a commit to sobolevn/cpython that referenced this issue Nov 16, 2023
JelleZijlstra added a commit that referenced this issue Dec 2, 2023
)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
…python#112143)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 new features, bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants