From 296cb3c1131c7379d27668da7d5cfa9278a6eb79 Mon Sep 17 00:00:00 2001 From: David McDonald Date: Sat, 29 Mar 2025 15:48:24 -0500 Subject: [PATCH] Code Analysis: Give pass to 'volatility3' Also moves some code into a private method with a docstring in the visitor class. --- test/volatility3_code_analysis.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/test/volatility3_code_analysis.py b/test/volatility3_code_analysis.py index ee1a54ce2..100ad3074 100644 --- a/test/volatility3_code_analysis.py +++ b/test/volatility3_code_analysis.py @@ -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