Skip to content

🐛 Coerce TyperArgument help with cleandoc like TyperOption - #1963

Closed
00200200 wants to merge 2 commits into
fastapi:masterfrom
00200200:fix/lazy-argument-help
Closed

00200200 wants to merge 2 commits into
fastapi:masterfrom
00200200:fix/lazy-argument-help

Conversation

@00200200

Copy link
Copy Markdown

Pull Request

Discussion: #1953

Description

TyperOption runs inspect.cleandoc(help) in its constructor, which also
coerces lazy str proxies (e.g. Django gettext_lazy) to real strings.
TyperArgument did not, so non-rich --help crashed with:

TypeError: expected string or bytes-like object

when Argument help was a non-str proxy and no extra metadata forced an
f-string coercion.

This applies the same cleandoc step to TyperArgument.

Checklist

  • This PR is an obvious typo fix, or it links to a GitHub Discussion for the proposed code change.
  • I added tests for the change.
  • The new or updated tests fail on the main branch and pass on this PR.
  • Coverage stays at 100%.
  • The documentation explains the change if needed.

Lazy str proxies (e.g. Django gettext_lazy) passed as Argument help
crashed non-rich --help because get_help_record returned a non-str.
Apply inspect.cleandoc the same way TyperOption already does.
inspect.cleandoc uses expandtabs via __getattr__, so the stand-in __str__ was never executed and coverage-combine failed under 100%.

@svlandeg svlandeg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing as violating the contribution guidelines - this has been discussed but not approved for a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants