Code Analysis: Give pass to 'volatility3'

Also moves some code into a private method with a docstring in the
visitor class.
This commit is contained in:
David McDonald
2025-03-29 15:49:33 -05:00
parent f72b717c00
commit 296cb3c113
+12 -5
View File
@@ -165,13 +165,16 @@ class ModuleVisitor(NodeVisitor):
def violations(self):
return self._violations
def enter_ImportFrom(self, node: ast.ImportFrom):
if not node.module:
return
def _check_vol3_import_from(self, node: ast.ImportFrom):
"""
Ensure that the only thing imported from a volatility3 module (apart
from the root volatility3 module) are functions and modules. This
prevents re-exporting of classes and variables from modules that use
them.
"""
if (
node.module
and node.module.startswith("volatility3")
and node.module.startswith("volatility3.") # Give a pass to volatility3 module
and node.module != "volatility3.framework.constants._version" # make an exception for this
):
for name in node.names:
@@ -198,6 +201,10 @@ class ModuleVisitor(NodeVisitor):
)
)
def enter_ImportFrom(self, node: ast.ImportFrom):
self._check_vol3_import_from(node)
def enter_ClassDef(self, node: ast.ClassDef) -> Any:
logger.debug("Entering class %s", node.name)
clazz = None