Fully typed `functools.partial`
Hello everyone! Recently I was curious about whether it is possible to create a fully typed `functools.partial` version. Because currently only return type is taken into account. So, I came up with the mypy plugin to type all the callable parameters during the partial application process and the final call. It works pretty well! Source: https://github.com/dry-python/returns/blob/master/returns/curry.py#L7 Plugin: https://github.com/dry-python/returns/blob/master/returns/contrib/mypy/_curr... Tests: https://github.com/dry-python/returns/tree/master/typesafety/test_curry I thought that mypy team might be interested in porting this (or similar) solution into the core. I would also be happy to receive any feedback on the code itself or the solution in general. Thanks a lot for building mypy, it is awesome! Best, Nikita Sobolev https://github.com/sobolevn
Very interesting. Would you be willing to rework your plugin into a PR for mypy, specifically targeted at functions.partial? On Fri, Apr 17, 2020 at 01:42 Никита Соболев <n.a.sobolev@gmail.com> wrote:
Hello everyone!
Recently I was curious about whether it is possible to create a fully typed `functools.partial` version. Because currently only return type is taken into account.
So, I came up with the mypy plugin to type all the callable parameters during the partial application process and the final call. It works pretty well!
Source: https://github.com/dry-python/returns/blob/master/returns/curry.py#L7 Plugin: https://github.com/dry-python/returns/blob/master/returns/contrib/mypy/_curr... Tests: https://github.com/dry-python/returns/tree/master/typesafety/test_curry
I thought that mypy team might be interested in porting this (or similar) solution into the core. I would also be happy to receive any feedback on the code itself or the solution in general.
Thanks a lot for building mypy, it is awesome!
Best, Nikita Sobolev https://github.com/sobolevn _______________________________________________ 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/
-- --Guido (mobile)
Sure, I'd be happy to. I cannot say that I know from where to start, however :) пт, 17 апр. 2020 г. в 18:33, Guido van Rossum <guido@python.org>:
Very interesting. Would you be willing to rework your plugin into a PR for mypy, specifically targeted at functions.partial?
On Fri, Apr 17, 2020 at 01:42 Никита Соболев <n.a.sobolev@gmail.com> wrote:
Hello everyone!
Recently I was curious about whether it is possible to create a fully typed `functools.partial` version. Because currently only return type is taken into account.
So, I came up with the mypy plugin to type all the callable parameters during the partial application process and the final call. It works pretty well!
Source: https://github.com/dry-python/returns/blob/master/returns/curry.py#L7 Plugin: https://github.com/dry-python/returns/blob/master/returns/contrib/mypy/_curr... Tests: https://github.com/dry-python/returns/tree/master/typesafety/test_curry
I thought that mypy team might be interested in porting this (or similar) solution into the core. I would also be happy to receive any feedback on the code itself or the solution in general.
Thanks a lot for building mypy, it is awesome!
Best, Nikita Sobolev https://github.com/sobolevn _______________________________________________ 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/
-- --Guido (mobile)
On Fri, 17 Apr 2020 at 16:58, Никита Соболев <n.a.sobolev@gmail.com> wrote:
Sure, I'd be happy to.
I cannot say that I know from where to start, however :)
"Bundled" plugins in mypy live here https://github.com/python/mypy/tree/master/mypy/plugins (mostly one plugin per file, there are some examples for existing stdlib plugins like ctypes, enum, dataclasses) The plugin hooks should be then added to `DefaultPlugin` in `default.py`. The tests can probably go into https://github.com/python/mypy/blob/master/test-data/unit/check-default-plug... (not really important where to put them) If you will make a PR, then someone will likely guide you through if there are issues. Can't guarantee a quick response however. -- Ivan
Thanks a lot for the tip! I will send a PR as soon as this feature will be stable enough. Today I have solved all issues with `TypeType` and `Instance.__call__`. There's still `Overloaded` left. Which is completely different. I hope to finish everything before May. сб, 18 апр. 2020 г. в 12:58, Ivan Levkivskyi <levkivskyi@gmail.com>:
On Fri, 17 Apr 2020 at 16:58, Никита Соболев <n.a.sobolev@gmail.com> wrote:
Sure, I'd be happy to.
I cannot say that I know from where to start, however :)
"Bundled" plugins in mypy live here https://github.com/python/mypy/tree/master/mypy/plugins (mostly one plugin per file, there are some examples for existing stdlib plugins like ctypes, enum, dataclasses) The plugin hooks should be then added to `DefaultPlugin` in `default.py`. The tests can probably go into https://github.com/python/mypy/blob/master/test-data/unit/check-default-plug... (not really important where to put them)
If you will make a PR, then someone will likely guide you through if there are issues. Can't guarantee a quick response however.
-- Ivan
participants (3)
-
Guido van Rossum
-
Ivan Levkivskyi
-
Никита Соболев