Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions nominal_refactor_advisor/refactors/return_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from nominal_refactor_advisor.refactors.answered_method import AnsweredMethod, AnsweredUse
from nominal_refactor_advisor.type_checker_session import SourceTexts, TypeCheckerSession

_shared_type_checker_session: TypeCheckerSession | None = None


def _tuple_return_kind(node: ast.Return) -> str | None:
"""Classify a return statement as zero-or-one tuple, or None if other."""
Expand Down Expand Up @@ -179,11 +181,16 @@ def add(file_path: str, start: int, end: int, text: str) -> None:
add(resolved_class.file_path, start, end, new_annotation)

answered = AnsweredMethod(snapshot, base, function)
session = TypeCheckerSession.started(SourceTexts(snapshot.parsed_modules))
shared = _shared_type_checker_session
owned_session = shared is None
session = shared or TypeCheckerSession.started(
SourceTexts(snapshot.parsed_modules)
)
try:
calls = answered.answering_calls(session)
finally:
session.stop()
if owned_session:
session.stop()

for use in calls:
geo = geometry(use.file_path)
Expand Down
Loading