Skip to content
Advertisement

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?

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement