:bug: Fix help extraction implementation and priority
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sebastián Ramírez · committed by Sebastián Ramírez · parent b4fa061 · Browse files · 1 file·+28 added−17 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+28 added−17 removed
- other:+28 added−17 removed
Provenance
- Commit
0086b7b- Tree
4190cc6- Author
Sebastián Ramírez <tiangolo@gmail.com>- Committer
Sebastián Ramírez <tiangolo@gmail.com>- Parent
b4fa061
1 file changed+28 added−17 removed
modified:typer/main.py+28 added-17 removed
259 unmodified lines260 return None261 262 263 def solve_typer_info_help(typer_info: TyperInfo) -> str:264- # Priority 1a: Value was set in app.add_typer()264+ # Priority 1: Explicit value was set in app.add_typer()265 if not isinstance(typer_info.help, DefaultPlaceholder):266 return inspect.cleandoc(typer_info.help or "")267- # Priority 1b: Value was set in app.add_typer(), in callback docstring267+ # Priority 2: Explicit value was set in sub_app.callback()268+ try:269+ callback_help = typer_info.typer_instance.registered_callback.help270+ if not isinstance(callback_help, DefaultPlaceholder):271+ return inspect.cleandoc(callback_help or "")272+ except AttributeError:273+ pass274+ # Priority 3: Explicit value was set in sub_app = typer.Typer()275+ try:276+ instance_help = typer_info.typer_instance.info.help277+ if not isinstance(instance_help, DefaultPlaceholder):278+ return inspect.cleandoc(instance_help or "")279+ except AttributeError:280+ pass281+ # Priority 4: Implicit inference from callback docstring in app.add_typer()282 if typer_info.callback:283 doc = inspect.getdoc(typer_info.callback)284 if doc:285 return doc286+ # Priority 5: Implicit inference from callback docstring in @app.callback()287 try:273- # Priority 2a: Value was set in @subapp.callback()274- doc = typer_info.typer_instance.registered_callback.help275- if not isinstance(doc, DefaultPlaceholder):276- return inspect.cleandoc(doc or "")277- # Priority 2b: Value was set in @subapp.callback(), in callback docstring278- doc = inspect.getdoc(typer_info.typer_instance.registered_callback.callback)279- if doc:280- return doc288+ callback = typer_info.typer_instance.registered_callback.callback289+ if not isinstance(callback, DefaultPlaceholder):290+ doc = inspect.getdoc(callback or "")291+ if doc:292+ return doc293 except AttributeError:294 pass295+ # Priority 6: Implicit inference from callback docstring in typer.Typer()296 try:284- # Priority 3a: Value set in subapp = typer.Typer()285- instance_value = typer_info.typer_instance.info.help286- if not isinstance(instance_value, DefaultPlaceholder):287- return inspect.cleandoc(instance_value or "")288- doc = inspect.getdoc(typer_info.typer_instance.callback)289- if doc:290- return doc297+ instance_callback = typer_info.typer_instance.info.callback298+ if not isinstance(instance_callback, DefaultPlaceholder):299+ doc = inspect.getdoc(instance_callback)300+ if doc:301+ return doc302 except AttributeError:303 pass304 # Value not set, use the default305 return typer_info.help.value427 unmodified lines