Skip to content

Conversation

@StabbarN
Copy link
Collaborator

I'd like to document an alternative to an antipattern that I found several times and had to refactor. It'd be nice to have a section to point to :).

With `c and h.div["hi"]`, mypy must assume the result is either the left operand (C | None) or the right operand (Element).
Because C.__bool__ has no declared return type, mypy can’t narrow based on truthiness and keeps the union as C | None | Element, which doesn’t fit Node | None.
@StabbarN StabbarN marked this pull request as ready for review August 29, 2025 17:48
@StabbarN StabbarN requested a review from pelme August 29, 2025 17:49
@StabbarN
Copy link
Collaborator Author

StabbarN commented Sep 3, 2025

Discussed with Pelme. A short note in https://htpy.dev/usage/#conditional-rendering would be more appropiate.

@StabbarN StabbarN closed this Sep 3, 2025
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.

1 participant