pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

Display default parameter values instead of ellipses

Open heejaechang opened this issue 3 years ago • 1 comments

Discussed in https://github.com/microsoft/pylance-release/discussions/2616

Originally posted by fj128 September 6, 2021 When I do

from pathlib import Path
help(Path().mkdir)

it prints

Help on method mkdir in module pathlib:

mkdir(mode=511, parents=False, exist_ok=False) method of pathlib.WindowsPath instance
    Create a new directory at this given path.

help(pathlib.Path.mkdir) works similarly (need to import pathlib first of course).

Hovering over the definition on the other hand gives

(method) mkdir: (mode: int = ..., parents: bool = ..., exist_ok: bool = ...) -> None
Create a new directory at this given path.

I would very much prefer seeing actual default values and I hope that it's obvious that in this case it's nontrivial to guess but important to know what they are.

I understand that there might be interesting corner cases, for example what if the default value is an object() sentinel? But if the built-in help() ignores the issue, you can too, I think.

I suspect that the lack of this feature (or an active misfeature, since it should be easier to do what help() does instead of going out of your way replacing default values with ellipses) has something to do with typeshed-fallback/stdlib/builtins.pyi and other stub files which understandably use ellipses instead of default parameters (fun fact: open() has 7 overloads there). If that's the case, please don't let the perfect be the enemy of the good, I'd much prefer seeing non-stubbed functions with actual default values and stubbed functions with ellipses (until someone does the boring thing) than for both to suck uniformly.

heejaechang avatar Sep 07 '22 05:09 heejaechang

we should try to do what we do for doc string for default value for function signature.

heejaechang avatar Sep 07 '22 05:09 heejaechang