Skip to content

fix: enhance IntelliSense support by adding type hints for Prompt att…#28

Merged
CorentinGS merged 1 commit into
masterfrom
fix/intellisense_prompts
Dec 8, 2025
Merged

fix: enhance IntelliSense support by adding type hints for Prompt att…#28
CorentinGS merged 1 commit into
masterfrom
fix/intellisense_prompts

Conversation

@CorentinGS
Copy link
Copy Markdown
Contributor

…ributes

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances IntelliSense support for prompt context managers by adding comprehensive type hints to PromptContextManager and AsyncPromptContextManager classes. The changes improve developer experience by enabling better IDE autocomplete and type checking for attributes that are dynamically forwarded from the wrapped Prompt object.

Key Changes:

  • Added type hint class attributes for forwarded Prompt attributes to enable IntelliSense
  • Added return type annotations to all context manager methods (__init__, __enter__, __exit__, __aenter__, __aexit__, __getattr__, __repr__, __str__)
  • Added explicit type annotations to instance variables in __init__ methods
  • Added compile_variables method to both context managers to explicitly forward this method from the wrapped Prompt
  • Added type hints to the _PromptContextMixin class for shared attributes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread basalt/prompts/models.py
Comment on lines +407 to +409
def compile_variables(self, variables: dict[str, Any]) -> Prompt:
"""Forward compile_variables to wrapped Prompt."""
return self._prompt.compile_variables(variables)
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compile_variables method was added to AsyncPromptContextManager but there's no test coverage for it. Consider adding a test similar to test_wrapper_forwards_all_prompt_methods in tests/prompts/test_context_manager.py but for the async version to ensure this method is properly tested.

Copilot uses AI. Check for mistakes.
Comment thread basalt/prompts/models.py
self._tag: str | None = tag
self._variables: dict[str, Any] | None = variables
self._from_cache: bool = from_cache
self._context_token: Any = None
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type hint for _context_token could be more specific. Since _current_prompt_context.set() returns a Token object from the contextvars module, consider changing the type from Any to contextvars.Token[dict[str, Any] | None] | None for better type safety. You'll need to import Token from contextvars.

Copilot uses AI. Check for mistakes.
Comment thread basalt/prompts/models.py
self._tag: str | None = tag
self._variables: dict[str, Any] | None = variables
self._from_cache: bool = from_cache
self._context_token: Any = None
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type hint for _context_token could be more specific. Since _current_prompt_context.set() returns a Token object from the contextvars module, consider changing the type from Any to contextvars.Token[dict[str, Any] | None] | None for better type safety. You'll need to import Token from contextvars.

Copilot uses AI. Check for mistakes.
@CorentinGS CorentinGS merged commit 773b581 into master Dec 8, 2025
11 checks passed
@CorentinGS CorentinGS deleted the fix/intellisense_prompts branch January 23, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants