Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retain return type from @dispatcher.span #17817

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

GICodeWarrior
Copy link
Contributor

@GICodeWarrior GICodeWarrior commented Feb 14, 2025

Attempt to fix #16915

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Your pull-request will likely not be merged unless it is covered by some form of impactful unit testing.

  • I added new unit tests to cover this change
  • I believe this change is already covered by existing unit tests

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added Google Colab support for the newly added notebooks.
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I ran make format; make lint to appease the lint gods

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Feb 14, 2025
@GICodeWarrior GICodeWarrior marked this pull request as draft February 14, 2025 04:20
@GICodeWarrior
Copy link
Contributor Author

OK, I believe the type checking is working better now.

However, this has uncovered typing issues in 11 other files. 🤔

@GICodeWarrior
Copy link
Contributor Author

Some of these might be actual bugs.

For example, RESPONSE_TYPE can be AsyncStreamingResponse, and if it is, the get_response call on line 47 below needs to be awaited, right?

def _query(self, query_bundle: QueryBundle) -> RESPONSE_TYPE:
response = self._query_engine._query(query_bundle)
if self.max_retries <= 0:
return response
typed_response = (
response if isinstance(response, Response) else response.get_response()
)

RESPONSE_TYPE = Union[
Response, StreamingResponse, AsyncStreamingResponse, PydanticResponse
]

@GICodeWarrior
Copy link
Contributor Author

Note, commit 9303917 is a pretty good branching point before I went down a deep rabbit hole. (8 mypy errors remaining there)

@GICodeWarrior
Copy link
Contributor Author

d54996e gets back to 7 mypy errors (better than before the rabbit hole)

@GICodeWarrior
Copy link
Contributor Author

For these remaining mypy errors, I'm not sure I know the code well enough to determine whether it's best to "fix" the types, squelch the error (with a cast or type ignore), or if there are potential bugs in the code.

llama_index/core/indices/common_tree/base.py:222: error: Incompatible types in assignment (expression has type "tuple[str]", variable has type "list[tuple[str, str]]")  [assignment]
llama_index/core/tools/retriever_tool.py:84: error: "BaseNode" has no attribute "text_template"  [attr-defined]
llama_index/core/tools/retriever_tool.py:109: error: "BaseNode" has no attribute "text_template"  [attr-defined]
llama_index/core/extractors/metadata_extractors.py:503: error: Item "list[Any]" of "Any | list[Any]" has no attribute "dict"  [union-attr]
llama_index/core/evaluation/retrieval/evaluator.py:48: error: "BaseNode" has no attribute "text"  [attr-defined]
llama_index/core/evaluation/retrieval/evaluator.py:87: error: "BaseNode" has no attribute "text"  [attr-defined]
llama_index/core/evaluation/retrieval/evaluator.py:88: error: Argument 1 to "append" of "list" has incompatible type "BaseNode"; expected "TextNode"  [arg-type]

https://github.com/run-llama/llama_index/actions/runs/13335762370/job/37250483650?pr=17817

@GICodeWarrior
Copy link
Contributor Author

Reworked commits to be a little more cohesive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: Prevent @dispatcher.span Return Type Erasure
1 participant