Replies: 1 comment
-
One way to handle this: from typing import Callable
def name_function[T: Callable](function: T, name: str) -> T:
"""Set the name of a function."""
function.__name__ = name
return function
def named_function[T: Callable](name: str) -> Callable[[T], T]:
"""Decorator to set the name of a function."""
return lambda function: name_function(function, name)
@named_function('custom type name to display or an empty string')
def parse_custom_class(value: str) -> CustomClass:
return CustomClass(value * 2) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
I've been trying to use typer with custom types, recently a version was released with such a support (thx!).
However, when specifying a
parser
for atyper.Option(...)
, the "type" description in--help
of the cli shows the parser function name as the argument type.For example, using the example provided in docs:
(Note PARSE_CUSTOM_CLASS)
Operating System
macOS
Operating System Details
No response
Typer Version
0.9.0
Python Version
3.9.13
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions