6 ms·
I don’t disagree with the “early TypeScript” comparison, but what’s the issue with args, *kwargs?
by tpict 4y ago
I don’t disagree with the “early TypeScript” comparison, but what’s the issue with args, *kwargs?
- matsemann 4y agoThe 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.*
- henbruas 4y agoWhile 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 https://github.com/sbdchd/celery-types
- matsemann 4y agoOnly since 3.10, though, before that it was actually impossible to type the decorators correctly.
- dragonwriter 4y ago> 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.
- Too 4y agoParamSpec from 3.10 is adding some improvements to type hinting decorators and wrapper functions that just forward args and kwargs. https://peps.python.org/pep-0612/ https://peps.python.org/pep-0612/