Skip to content

How to narrowing a dataclass return type #1613

Answered by erictraut
jackjyq asked this question in Q&A
Discussion options

You must be logged in to vote

If you're sure that table.row is not None, you can add an assert statement to this effect. This documents your assumption for yourself, other readers of your code, and for static type checkers.

if table := query(1):
    assert table.row is not None
    print(table.row.cell)

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@jackjyq
Comment options

@erictraut
Comment options

@jackjyq
Comment options

Answer selected by jackjyq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants