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

Feature/redbox 4 setup mypy for type hinting testing #24

Merged
merged 13 commits into from
Feb 19, 2024

Conversation

gecBurton
Copy link
Collaborator

@gecBurton gecBurton commented Feb 16, 2024

Context

mypy checks the code for type errors.

Changes proposed in this pull request

  1. mypy has been added to the Makefile as checktypes and is used in CI.
  2. the code has been adjusted to pass the checktypes.
  3. we are not following-imports in the legacy app as the effort doesnt justify the benefit for code that wont be around much longer.
  4. following the warning documented at https://docs.pydantic.dev/2.0/usage/computed_fields/ I have added # type: ignore where we are using @computed_field.
  5. I have moved some of the existing tests so that the directory structure of the tests copies that of the source code.
  6. typing.List as been replaced with list etc

Guidance to review

  • CI runs
  • code changes are non-functional

Link to JIRA ticket

https://technologyprogramme.atlassian.net/browse/REDBOX-4

Things to check

- [ ] I have added any new ENV vars in all deployed environments

@@ -143,10 +143,10 @@ def merge_chunk_metadata(meta_in: List[Dict]) -> Dict:
Combine metadata for multiple chunks from the same document.
"""
# collect all the possible key values
all_keys = set()
all_keys: set = set()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why mypy insists we do this i will never know!


@computed_field
def model_type(self) -> str:
return self.__class__.__name__
Copy link
Collaborator Author

@gecBurton gecBurton Feb 17, 2024

Choose a reason for hiding this comment

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

I wasn't sure that this would resolve properly for child classes, i.e. would this fucntion always return "PersistableModel". however there are two existing test for this that show this working as expected

"""
if os.environ["CACHE_LLM_RESPONSES"] == "true":
set_llm_cache(SQLiteCache(database_path=os.environ["CACHE_LLM_DB"]))

self.docs_with_sources_chain = load_qa_with_sources_chain(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@@ -77,7 +77,7 @@ def delete_item(self, item_uuid: str, model_type: str):

def delete_items(self, item_uuids: List[str], model_type: str):
target_index = f"{self.root_index}-{model_type.lower()}"
result = self.es_client.mdelete(index=target_index, body={"ids": item_uuids})
result = self.es_client.mdelete(index=target_index, body={"ids": item_uuids}) # type: ignore
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

does mdelete exist?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is a typo and I've never actually called this method to spot it

legacy_app/utils.py Outdated Show resolved Hide resolved
chat_history: Optional[List] = [],
callbacks: Optional[List] = [],
) -> dict:
chat_history: Optional[list] = None,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@lmwilkigov lmwilkigov merged commit d16e045 into main Feb 19, 2024
1 check passed
@lmwilkigov lmwilkigov deleted the feature/REDBOX-4-setup-mypy-for-type-hinting-testing branch February 19, 2024 14:04
lmwilkigov added a commit that referenced this pull request Mar 8, 2024
…type-hinting-testing

Feature/redbox 4 setup mypy for type hinting testing
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.

2 participants