New submission from Raymond Hettinger <raymond.hettin...@gmail.com>:
Python's help() function does not display overloaded function signatures. For example, this code: from typing import Union class Smudge(str): @overload def __getitem__(self, index: int) -> str: ... @overload def __getitem__(self, index: slice) -> 'Smudge': ... def __getitem__(self, index: Union[int, slice]) -> Union[str, 'Smudge']: 'Return a smudged character or characters.' if isinstance(index, slice): start, stop, step = index.indices(len(self)) values = [self[i] for i in range(start, stop, step)] return Smudge(''.join(values)) c = super().__getitem__(index) return chr(ord(c) ^ 1) Currently gives this help: __getitem__(self, index: Union[int, slice]) -> Union[str, ForwardRef('Smudge')] Return a smudged character or characters. What is desired is: __getitem__(self, index: int) -> str __getitem__(self, index: slice) -> ForwardRef('Smudge') Return a smudged character or characters. The overload() decorator is sufficient for informing a static type checker but insufficient for informing a user or editing tool. ---------- messages: 401052 nosy: rhettinger priority: normal severity: normal status: open title: Teach help about typing.overload() _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45100> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com