Feature request: don't discard original functions when using @overload
I have been working on a stub validator that can import stubs and real packages side-by-side and report on inconsistencies. However, it can't do anything with @overload functions as they are discarded by the @overload implementation. It would be great if instead of throwing these away, they are kept in a list associated with an `__overloads__` attribute. I could create this as an issue in the GH repo, but thought I would float it here first to see what others think. Thanks Graham
Have you thought about how to implement your proposal? The @overload decorator would have to use frame inspection (i.e. sys._getframe()) in order to be able to store this in the class or globals. I'm not entirely against this, seeing how the typing module already uses sys._getframe() in a few places (for example to find out the module name), but it would definitely require some very subtle code. Another thing you could try would be essentially monkey-patching. Write your ideal @overload implementation, and just do ``` import typing def my_overload(func): ... typing.overload = my_overload ``` This way you should be able to do what your tool needs without waiting for Python 3.10, as long as you are careful to do the monkey-patching before importing your target modules. On Mon, Jun 15, 2020 at 10:42 AM Graham Wheeler <gram@geekraver.com> wrote:
I have been working on a stub validator that can import stubs and real packages side-by-side and report on inconsistencies. However, it can't do anything with @overload functions as they are discarded by the @overload implementation.
It would be great if instead of throwing these away, they are kept in a list associated with an `__overloads__` attribute.
I could create this as an issue in the GH repo, but thought I would float it here first to see what others think.
Thanks Graham _______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: guido@python.org
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>
Unrelated to the feature request, but as of fairly recently mypy ships with a stub validator called stubtest. There's a lot of room for improvement in this space, so would be interested in learning more about your work! :-)
Hi Shantanu Did not know about stubtest. I took a look at it and it looks like it covers everything I was already doing and more. Thanks for pointing it out! -Graham On Mon, Jun 15, 2020 at 11:26 AM Shantanu Jain <hauntsaninja@gmail.com> wrote:
Unrelated to the feature request, but as of fairly recently mypy ships with a stub validator called stubtest. There's a lot of room for improvement in this space, so would be interested in learning more about your work! :-)
You can also try https://github.com/typeddjango/pytest-mypy-plugins It has a bit different design. But solves the same problem. вт, 16 июн. 2020 г. в 02:32, Graham Wheeler <gram@geekraver.com>:
Hi Shantanu
Did not know about stubtest. I took a look at it and it looks like it covers everything I was already doing and more. Thanks for pointing it out!
-Graham
On Mon, Jun 15, 2020 at 11:26 AM Shantanu Jain <hauntsaninja@gmail.com> wrote:
Unrelated to the feature request, but as of fairly recently mypy ships with a stub validator called stubtest. There's a lot of room for improvement in this space, so would be interested in learning more about your work! :-)
_______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: n.a.sobolev@gmail.com
participants (4)
-
Graham Wheeler -
Guido van Rossum -
Shantanu Jain -
Никита Соболев