Re:Python 3.11.0 final is now available
by tpict on Tuesday October 25, 2022 @09:02AM
(#33329902)
I don’t disagree with the “early TypeScript” comparison, but what’s the issue with args, *kwargs?
[ Parent
| on HN ]
Re:Python 3.11.0 final is now available
by matsemann on Tuesday October 25, 2022 @09:54AM
(#33330485)
The problem is that you lose all help from tooling/IDEs. Like in Celery, the definition is "shared_task(*args, *kwargs)". This gives you no indication of what parameters you actually can use. Opening up the code doesn't help, as it's many layers down. The decorated function ends up untyped, but with some new methods on it that again are untyped. But like originalfunction.delay(...) should have the params of the original decorated function. But no, all that is lost. Just pray that the docs are correct.*
Re:Python 3.11.0 final is now available
by henbruas on Tuesday October 25, 2022 @11:03AM
(#33331492)
While it's of course not ideal, stub files can help with this issue. For example you can get stubs for Celery that make both `shared_task` and `delay` properly typed: https://github.com/sbdchd/celery-types
Re:Python 3.11.0 final is now available
by matsemann on Wednesday October 26, 2022 @02:18AM
(#33340397)
Only since 3.10, though, before that it was actually impossible to type the decorators correctly.
Re:Python 3.11.0 final is now available
by dragonwriter on Wednesday October 26, 2022 @12:10PM
(#33345810)
> Only since 3.10, though, before that it was actually impossible to type the decorators correctly.
There were type gymnastics you could do using overloads to reach any arbitrary level of coverage, but it was ugly and always short of fully general.
ParamSpec from 3.10 is adding some improvements to type hinting decorators and wrapper functions that just forward args and kwargs.