How to type hint a union of static modules?

Consider the following code:

PyCharm automatically senses that this is a module that could refer to one or more backing libraries.

Is it possible to specify this manually for other module variables as well? Something like the following:

from pyqtgraph.Qt import QtWidgets
QtWidgets: Union[PyQt5.QtWidgets.pyi, PySide2.QtWidgets.pyi] # <-- I want to add this type hint

Behind the scenes, pyqtgraph is dynamically constructing dummy QtWidgets to point to one of several libraries at runtime, but PyCharm doesn't know this. Is there a way for me to manually add that type hint (QtWidgets.pyi) to a module that I import (In this case, pyqtgraph.Qt.QtWidgets)?




Please sign in to leave a comment.