This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients rhettinger
Date 2021-09-04.18:03:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1630778608.65.0.813637953031.issue45100@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-09-04 18:03:28rhettingersetrecipients: + rhettinger
2021-09-04 18:03:28rhettingersetmessageid: <1630778608.65.0.813637953031.issue45100@roundup.psfhosted.org>
2021-09-04 18:03:28rhettingerlinkissue45100 messages
2021-09-04 18:03:28rhettingercreate