Skip to content

SymbolTableBuilder crashes on relative project_dir: eager relative_to() in _add_class next() default #90

Description

@rahlk

Pre-existing bug on main (verified byte-identical at 2cab542), discovered while verifying the #80 fix branch: constructing SymbolTableBuilder with a relativeproject_dir crashes analysis of any file containing a class.

Symptom

SymbolTableBuilder(Path("test/fixtures/single_functionalities/method_call_resolution"), None) \
.build_pymodule_from_file(Path("test/fixtures/.../main.py"))
# ValueError: '/abs/path/.../main.py' is not in the subpath of 'test/fixtures/...'

Root cause

In _add_class (codeanalyzer/syntactic_analysis/symbol_table_builder.py:202-209 on main), the Jedi-goto fallback signature is passed as next()'s default argument, so it is computed eagerly even when Jedi succeeds:

signature=next(
(d.full_namefordindefinitionsifd.type=="class"),
f"{Path(script.path).relative_to(self.project_dir)...}.{class_name}"
)

script.path is always absolute (Jedi resolves it), so relative_to(self.project_dir) raises ValueError whenever project_dir is relative. The except Exception handler below doesn't save it: it recomputes the identical expression and raises uncaught.

Fix direction

Normalize once in __init__: self.project_dir = Path(project_dir).resolve(). (Alternatively make the fallback lazy, but resolving at the boundary fixes every downstream relative_to in one place, including _callables.) Regression test: build a module via a builder constructed with a relative path.

Every current in-repo caller happens to pass resolved paths (e.g. test/conftest.py fixtures), which is why the suite never hits it — library consumers won't be so lucky.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions