Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Cannot instantiate typing.Optional [closed]

I have such a method:

def select_unassigned_variable(self, variables: List[V]) -> Optional(V):

I want this to return something of type V or None in some cases. But I get such error:

TypeError: Cannot instantiate typing.Optional

What should I change?

like image 689
Karol Avatar asked Jul 12 '26 12:07

Karol


1 Answers

You need to use it with brackets instead of parentheses:

def select_unassigned_variable(self, variables: List[V]) -> Optional[V]:

like you did with List.

like image 196
jmkjaer Avatar answered Jul 14 '26 00:07

jmkjaer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!