[New-bugs-announce] [issue45100] Teach help about typing.overload()

Raymond Hettinger report at bugs.python.org
Sat Sep 4 14:03:28 EDT 2021

New submission from Raymond Hettinger <raymond.hettinger at gmail.com>:

Python's help() function does not display overloaded function signatures.

For example, this code:

    from typing import Union

    class Smudge(str):

        def __getitem__(self, index: int) -> str:

        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 <report at bugs.python.org>

More information about the New-bugs-announce mailing list