Skip to content
Discussion options

You must be logged in to vote

The issue is that you're mixing type-hint syntax from different Python versions.

This part:

set[int]

only works in Python 3.9+.

So this is valid in Python 3.9+:

from typing import Optional, Tuple

in_switch: Optional[Tuple[int, set[int]]] = None

But if your interpreter or IDE is configured for Python 3.8 or older, set[int] is invalid as a type hint.

Use Set from typing for wider compatibility:

from typing import Optional, Tuple, Set

in_switch: Optional[Tuple[int, Set[int]]] = None

Similarly, this is already the compatible form:

from typing import Optional, List

items: Optional[List["Expr"]] = None

If you want the most compatible Python 3 style, write both like this:

from typing import List

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Bat-Script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug GitHub or a GitHub feature is not working as intended Programming Help Discussions around programming languages, open source and software development source:ui Discussions created via Community GitHub templates
2 participants