You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromdecoratorimportdecorator@decoratordefhandle_exceptions(method, *args, **kwargs):
"""Handle keyboard interruption while running a method."""try:
try:
returnmethod(*args, **kwargs)
exceptKeyboardInterrupt:
raiseUserMessageError("Execution stopped by user")
exceptUserMessageErroraserror:
print(colors.red|"\n".join(error.args), file=sys.stderr)
return1exceptUnsafeTemplateErroraserror:
print(colors.red|"\n".join(error.args), file=sys.stderr)
# DOCS https://github.com/copier-org/copier/issues/1328#issuecomment-1723214165return0b100
this decorator is then applied to plumbum.cli subcommand methods.
This works fine- the @decorator decorator ensures the wrapped method's signature doesn't change, so plumbum.cli's introspection still works. There are two downsides
@decorator is untyped
@decorator breaks if you add from __future__ import annotations to the file
I tried a different approach using a native decorator:
that works, unless you add from __future__ import annotations, because that import changes the behaviour of inspect.signature (see https://bugs.python.org/issue43355)
i'm guessing that's the exact issue that was causing me problems at the beginning of this journey...
How should I proceed?
The text was updated successfully, but these errors were encountered:
ultimately i found a way around by avoiding decorators entirely, but it would be nice if there was some further consideration given to the interaction between plumbum.cli, decorators, and from __future__ import annotations.
the copier project is using a decorator to wrap error handling around some
plumbum
methods, like so-see https://github.com/copier-org/copier/blob/5e98d21f35767de527c64da371045f4f018fa619/copier/cli.py
this decorator is then applied to plumbum.cli subcommand methods.
This works fine- the
@decorator
decorator ensures the wrapped method's signature doesn't change, soplumbum.cli
's introspection still works. There are two downsides@decorator
is untyped@decorator
breaks if you addfrom __future__ import annotations
to the fileI tried a different approach using a native decorator:
but this fails, presumably because
plumbum.cli
is relying on some element of the method signature thatfunctools.wraps
fails to forward.I tried instead-
that works, unless you add
from __future__ import annotations
, because that import changes the behaviour ofinspect.signature
(see https://bugs.python.org/issue43355)i'm guessing that's the exact issue that was causing me problems at the beginning of this journey...
How should I proceed?
The text was updated successfully, but these errors were encountered: