[issue46821] Introspection support for typing.overload

2022-02-21 Thread Jelle Zijlstra


Jelle Zijlstra  added the comment:

Thanks! Closing this as a duplicate.

--
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> Improve help() by making typing.overload() information 
accessible at runtime

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46821] Introspection support for typing.overload

2022-02-21 Thread Alex Waygood


Alex Waygood  added the comment:

Discussion of similar ideas in Issue45100

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46821] Introspection support for typing.overload

2022-02-21 Thread Jelle Zijlstra


New submission from Jelle Zijlstra :

Currently, the implementation of @overload 
(https://github.com/python/cpython/blob/59585d6b2ea50d7bc3a9b336da5bde61367f527c/Lib/typing.py#L2211)
 simply returns a dummy function and throws away the decorated function. This 
makes it virtually impossible for type checkers using the runtime function 
object to find overloads specified at runtime.

In pyanalyze, I worked around this by providing a custom @overload decorator, 
working something like this:

_overloads: dict[str, list[Callable]] = {}

def _get_key(func: Callable) -> str:
return f"{func.__module__}.{func.__qualname__}"

def overload(func):
key = _get_key(func)
_overloads.setdefault(key, []).append(func)
return _overload_dummy

def get_overloads_for(func):
key = _get_key(func)
return _overloads.get(key, [])

A full implementation will need more error handling.

I'd like to add something like this to typing.py so that other tools can also 
use this information.

--
assignee: Jelle Zijlstra
components: Library (Lib)
messages: 413671
nosy: AlexWaygood, Jelle Zijlstra, gvanrossum, kj, sobolevn
priority: normal
severity: normal
status: open
title: Introspection support for typing.overload
type: enhancement
versions: Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com