What is the correct type hint for x = []?
The type checker in my PyCharm editor flagged this as an error:
labelframes: List[ttk.LabelFrame] = []
'Optional' is not an option as in:
labelframes: List[Optional[ttk.LabelFrame]] = []
because the documentation for typing.Optional states that this is equivalent to:
labelframes: List[Union[ttk.LabelFrame, None]] = []
and [None] is not [].
I ought to mention that PyCharm doesn't like this either:
labelframes: List[Union[ttk.LabelFrame, None]] = [None]
Whatever type hint I try. PyCharm flags it as an error with, "Expected to return my type hint here, got no return," so I tried:
labelframes: Optional[List[ttk.LabelFrame, None]] = []
That didn't work.
I am aware that PEP 526 has numerous examples which follow the pattern:
x: List[str] = []