Open
Description
If I write:
from decorator import FunctionMaker
fm = FunctionMaker(lambda x: x)
print(f'{fm.defaults=}')
then I see
fm.defaults=None
However, the stubs show:
typeshed/stubs/decorator/decorator.pyi
Line 23 in ecd5141
and None
can't be assigned to tuple[Any, ...]
@donBarbos sorry for the ping, I just saw that you worked on these stubs a few months ago. Can you tell if it's accurate that defaults
should be tuple[Any, ...] | None
?
The inspect docs also note:
defaults is an n-tuple of default argument values corresponding to the last n positional parameters, or None if there are no such defaults defined
Activity
donBarbos commentedon Jun 16, 2025
sorry, my bad.
judging by source code I decided that the fields are set only if they are not None:
https://github.com/micheles/decorator/blob/143887ed562e83007271df94527eb8f4c269ed4c/src/decorator.py#L100-L111
so maybe for other arguments (which become fields) this also applies.
would you like to send PR? (or I can also send PR)
MarcoGorelli commentedon Jun 16, 2025
thanks!
i find the logic a bit surprising - these fields are initialised to an empty tuple, which then may get overwritten. so technically they can also be tuples
do you think a fix should be to
decorator
itself, something liketuple[Any, ...]
in the type stubs for each of these variables, as possibly some missingNone
? e.g.args: Sequence[str]
?
donBarbos commentedon Jun 16, 2025
I would prefer to list all the possible types for each of the fields, firstly because there are not so many of them, and secondly, each of them has its own possible types.
but before, yea, it's better to get rid of the default tuple in source code
MarcoGorelli commentedon Jun 17, 2025
Sure, thanks - I've started by opening a PR to them here: micheles/decorator#174