Avoidance of Wildcard Imports
When using PyQt, programmers may encounter lint warnings when importing all submodules using wildcard imports:
from PyQt4.QtCore import * from PyQt4.QtGui import *
This can lead to unnecessary warnings for unused imports. Several alternatives exist to address this issue.
Options
from PyQt4.QtCore import Qt, QPointF, QRectF from PyQt4.QtGui import QGraphicsItem, QGraphicsScene, ...
This approach imports only specified classes, which can lead to a long list of imports.
from PyQt4 import QtCore, QtGui
This requires prefixing all classes with their module name, which can be cumbersome.
# Avoid wildcard imports
Recommendation
The recommended practice is to avoid wildcard imports and use qualified names or abbreviations instead. Qualified names provide better clarity and avoid the risk of rebinding or accidental errors. Abbreviated imports can balance conciseness with clarity. Avoid using multiple as clauses or long import lists in a single statement for enhanced readability and debuggability.
The above is the detailed content of Why Should I Avoid Wildcard Imports in PyQt?. For more information, please follow other related articles on the PHP Chinese website!