You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This patch adds beartype for runtime type checking. This gives us the
best of both worlds: we do static type checking of our own library with
mypy, and we export our static types, but for clients who do not run
static type checking of their own code, runtime type checking in our
library can help them catch bugs earlier.
`tests/test_codex_tool.py::test_bad_argument_type` serves as an example:
this fails at initialization time of `CodexTool`, whereas without
runtime type checking, this would fail later (e.g., when the user calls
the `query` method on the object).
Because we're performing runtime type checking, some of the imports that
were behind `if TYPE_CHECKING` flags have to be moved to runtime. This
patch updates the linter config to allow imports that are only used for
type checking.
This patch also switches to consistent `from __future__ import
annotations` everywhere, stops using type hints deprecated by PEP 585,
and uses PEP 585 / PEP 604 syntax everywhere. This patch updates the
linter config to match this style.
beartype relies on `isinstance` for runtime type checks, which needs to
be taken into account when using mocks by overriding the `__class__`
attribute. This patch updates the tests accordingly.
project_id: Optional[str]=None, # TODO: update to uuid once project IDs are changed to UUIDs
103
-
fallback_answer: Optional[str]=None,
98
+
project_id: str|None=None, # TODO: update to uuid once project IDs are changed to UUIDs
99
+
fallback_answer: str|None=None,
104
100
read_only: bool=False,
105
-
) ->tuple[Optional[str], Optional[Entry]]:
101
+
) ->tuple[str|None, Entry|None]:
106
102
"""Query Codex to check if the Codex project contains an answer to this question and add the question to the Codex project for SME review if it does not.
107
103
108
104
Args:
109
105
question (str): The question to ask the Codex API.
110
-
project_id (:obj:`int`, optional): The ID of the project to query.
106
+
project_id (:obj:`str`, optional): The ID of the project to query.
111
107
If the client is authenticated with a user-level API Key, this is required.
112
108
If the client is authenticated with a project-level Access Key, this is optional. The client will use the Access Key's project ID by default.
113
109
fallback_answer (:obj:`str`, optional): Optional fallback answer to return if Codex is unable to answer the question.
"""Sets the fallback answer to use if the Codex project cannot answer the question."""
84
84
self._fallback_answer=value
85
85
86
-
defquery(self, question: str) ->Optional[str]:
86
+
defquery(self, question: str) ->str|None:
87
87
"""Asks an all-knowing advisor this question in cases where it cannot be answered from the provided Context. If the answer is not available, this returns a fallback answer or None.
0 commit comments