Skip to content

Unexpected return type #8149

Answered by erictraut
danpascu asked this question in Q&A
Jun 16, 2024 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

When a static type checker evaluates a call to a function, it uses only the function's signature (i.e. the parameter and return type annotations supplied in the function declaration) to evaluate the type returned by the function. It does not pay attention to the body of the function. In fact, you can omit the entire function body and replace it with ..., as is often done in type stub files. The types of the local variables and expressions within a function body (e.g. where you are calling reveal_type) have no bearing on the evaluation of calls to get_base_type.

One of the problems here is that you're using type forms that look like type expressions (such as str | None), but you're using t…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@erictraut
Comment options

Answer selected by danpascu
@danpascu
Comment options

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