You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
__init__.py imports MainWindow from plotting. However, MainWindow is fully exported from window, not plotting. While not incorrect python, this causes mypy to not be able to see QMainWindow super class methods when creating pyvistaqt.MainWindow instances.
e.g.
frompyvistaqtimportMainWindowwindow=MainWindow()
window.setWindowTitle('window') # mypy complains window has no attribute "setWindowTitle"
Also mypy<=0.961 does not yet fully support conditional imports (see Issue 1297 and 1393).
The fix for the first item is to either use a package wildcard import or import from the appropriate modules using the from ... import ... as ... notation:
Option 1: Explicit
...
else:
from .plottingimport (
BackgroundPlotterasBackgroundPlotter,
MultiPlotterasMultiPlotter,
QtInteractorasQtInteractor,
)
from .windowimportMainWindowasMainWindow
Option 2: Implicit
...
else:
from .plottingimport*from .windowimport*
The fix for the second item would simply be to raise the RuntimeError directly within the except clause and use the @cjerdonek workaround:
try:
fromqtpyimportQtCoreas_QtCoreexceptExceptionasexc:
QtCore=None# pylint: disable=invalid-nameraiseRuntimeError(f'No Qt binding was found, got: {exc}') fromexcelse:
QtCore=_QtCore# Do imports from ``plotting`` and ``window`` here
Modules and variables imported into the stub are not considered exported from the stub unless the import uses the import ... as ... form or the equivalent from ... import ... as ... form. (UPDATE: To clarify, the intention here is that only names imported using the form X as X will be exported, i.e. the name before and after as must be the same.)
However, as an exception to the previous bullet, all objects imported into a stub using from ... import * are considered exported. (This makes it easier to re-export all objects from a given module that may vary by Python version.)
If a file init.py uses the form “from .A import X”, symbol “A” is not private unless the name begins with an underscore (but “X” is still private).
A module can expose an all symbol at the module level that provides a list of names that are considered part of the interface. The all symbol indicates which symbols are included in a wildcard import.
PEP 484 requires redundant alias imports to identify modules as being re-exported. Adding these fixes the mypy error that it cannot find parent methods in child instances of `MainWindow`.
Fixes Issue pyvista#163
__init__.py
importsMainWindow
fromplotting
. However,MainWindow
is fully exported fromwindow
, notplotting
. While not incorrect python, this causes mypy to not be able to seeQMainWindow
super class methods when creatingpyvistaqt.MainWindow
instances.e.g.
Also
mypy<=0.961
does not yet fully support conditional imports (see Issue 1297 and 1393).The fix for the first item is to either use a package wildcard import or import from the appropriate modules using the
from ... import ... as ...
notation:Option 1: Explicit
Option 2: Implicit
The fix for the second item would simply be to raise the
RuntimeError
directly within theexcept
clause and use the @cjerdonek workaround:NOTE: PEP 484 states
and Pyright indicates
Note also that Pyright states
import A as A
is called a redundant module aliasfrom X import A as A
is called a redundant symbol aliasThe text was updated successfully, but these errors were encountered: