Open dkim286 opened 2 years ago
Code completion tools (such as IntelliSense) are unable to recognize the ctrl member variable's type:
ctrl
This does not break anything, but it's annoying to look at.
Code completion tool wrongly believes that ctrl is None due to its default value:
None
Use typing library to allow for type hinting without running into potential circular dependency issues.
typing
Before:
class MainWindow(ttk.Frame): def __init__(self, parent): super().__init__(parent) self.__create_home_widgets() self.__ctrl = None @property def ctrl(self): '''Controller.''' return self.__ctrl '''snip'''
Suggestion:
from typing import TYPE_CHECKING if TYPE_CHECKING: from pm.controller import Controller class MainWindow(ttk.Frame): def __init__(self, parent): super().__init__(parent) self.__create_home_widgets() self.__ctrl = None @property def ctrl(self) -> 'Controller': '''Controller.''' return self.__ctrl '''snip'''
More info: https://adamj.eu/tech/2021/05/13/python-type-hints-how-to-fix-circular-imports/
Description
Code completion tools (such as IntelliSense) are unable to recognize the
ctrl
member variable's type:This does not break anything, but it's annoying to look at.
Cause
Code completion tool wrongly believes that
ctrl
isNone
due to its default value:Fix
Use
typing
library to allow for type hinting without running into potential circular dependency issues.Before:
Suggestion:
More info: https://adamj.eu/tech/2021/05/13/python-type-hints-how-to-fix-circular-imports/