Skip to content

Getting reportOptionalCall error when assigning a variable to a bound method with if statements? #2251

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

You must be logged in to vote

The problem is that you're not handling the case where library contains a value other than "multiprocessing" or "concurrent".

There are a couple of ways you could fix this.

  1. Annotate the library parameter with the type Literal["concurrent", "multiprocessing"]. This tells the type checker that it will never contain a value other than these two literal values.
  2. Add an else clause that handles the case where library contains an unexpected value and call self._log_exception in that case.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by HunterAP23
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