From 8282eb1c7c6cfb6143b41d86ecd3a67d08979b39 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 13 Mar 2026 02:32:19 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Refactor:=20Remove=20unused=20`f?= =?UTF-8?q?ile=5Fpath`=20arg=20from=20`=5Fextract=5Fsymbols`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed the unused `file_path` argument from internal `_extract_symbols` and `_extract_import_symbols` methods in the AST parser to clean up the code. Also updated a test fixture to ensure `pre-python3.12` style annotations work properly, and excluded it from Ruff's UP040 fix so it won't be auto-updated to the `type` keyword. Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com> --- ruff.toml | 1 + src/exportify/analysis/ast_parser.py | 9 ++++----- tests/fixtures/sample_type_aliases.py | 17 ++++++++++------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/ruff.toml b/ruff.toml index 30145e3..74f5dde 100755 --- a/ruff.toml +++ b/ruff.toml @@ -32,6 +32,7 @@ exclude = [ "venv", "typings", "tests/fixtures/malformed.py", + "tests/fixtures/sample_type_aliases.py", ] extend-include = ["*.ipynb"] fix = true diff --git a/src/exportify/analysis/ast_parser.py b/src/exportify/analysis/ast_parser.py index a3c7bb6..4dc983f 100644 --- a/src/exportify/analysis/ast_parser.py +++ b/src/exportify/analysis/ast_parser.py @@ -69,8 +69,8 @@ def parse_file(self, file_path: Path, module_path: str) -> AnalysisResult: ) # Extract symbols (both defined and imported) - defined_symbols = self._extract_symbols(tree, file_path) - imported_symbols = self._extract_import_symbols(tree, file_path) + defined_symbols = self._extract_symbols(tree) + imported_symbols = self._extract_import_symbols(tree) all_symbols = defined_symbols + imported_symbols # Extract imports as strings for backward compatibility/caching @@ -88,12 +88,11 @@ def parse_file(self, file_path: Path, module_path: str) -> AnalysisResult: declared_all=declared_all, ) - def _extract_symbols(self, tree: ast.Module, file_path: Path) -> list[DetectedSymbol]: + def _extract_symbols(self, tree: ast.Module) -> list[DetectedSymbol]: """Extract all exportable symbols from AST. Args: tree: Parsed AST module - file_path: Path to source file (for error reporting) Returns: List of detected symbols @@ -254,7 +253,7 @@ def _determine_variable_type(self, name: str, annotation: ast.expr | None) -> Me # Default to variable return MemberType.VARIABLE - def _extract_import_symbols(self, tree: ast.Module, file_path: Path) -> list[DetectedSymbol]: + def _extract_import_symbols(self, tree: ast.Module) -> list[DetectedSymbol]: """Extract import statements as ParsedSymbol objects. Categorizes imports with heuristic metadata to help distinguish likely re-exports diff --git a/tests/fixtures/sample_type_aliases.py b/tests/fixtures/sample_type_aliases.py index 0e1426c..0025dcc 100644 --- a/tests/fixtures/sample_type_aliases.py +++ b/tests/fixtures/sample_type_aliases.py @@ -19,14 +19,17 @@ # Dummy usage of type aliases to keep static analyzers happy. test_file_path: FilePath | None = None +from typing import TypeAlias + + # Pre-3.12 style type aliases (X: TypeAlias = Y) -type FilePath = str | Path -type ModuleName = str -type RulePattern = str -type ExportName = str -type ErrorMessage = str -type ConfigDict = dict[str, str | int | bool | list[str]] -type NamePair = tuple[str, str] +FilePath: TypeAlias = str | Path +ModuleName: TypeAlias = str +RulePattern: TypeAlias = str +ExportName: TypeAlias = str +ErrorMessage: TypeAlias = str +ConfigDict: TypeAlias = dict[str, str | int | bool | list[str]] +NamePair: TypeAlias = tuple[str, str] # Python 3.12+ style type aliases (type X = Y) type FileContent = str