-
Notifications
You must be signed in to change notification settings - Fork 7.4k
added type annotations and __slots__ to the Python SDK #11394
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
base: main
Are you sure you want to change the base?
Conversation
I've also added __slots__ less so to improve efficiency and more to be sure there are no typos on assignments. There remain a few untyped parts where I could not find documentation of the types. These things are in particular: - Agent.Dsl - Agent.create_session() - DataSet.ParserConfig - I'm not sure if the documented parameters are complete. - Session.ask() - kwargs specific to agent/chat
| actual_keys = set(response.keys()) | ||
| if actual_keys == error_keys: | ||
| raise Exception(res.get("message")) | ||
| raise Exception(response.get("message")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed a bug here and fixed it while I was at it. Mentioned the bug here:
f007c1c#r170921731
| answer = json_data["answer"] | ||
| reference = json_data.get("reference", {}) | ||
| else: | ||
| raise Exception(f"Unknown session type: {self.__session_type}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed a missing else branch and fixed it while I was at it. I mentioned that here:
95fad5d#r170922254
| reference = json_data.get("reference", {}) | ||
| else: | ||
| raise Exception(f"Unknown session type: {self.__session_type}") | ||
| reference = json_data.get("reference") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I removed the default parameter to the get() method here. Creating an empty dict in any case here is useless overhead, especially since below there is an if reference ... anyway!
I've also added
__slots__less so to improve efficiency and more to be sure there are no typos on assignments.There remain a few untyped parts where I could not find documentation of the types. These things are in particular:
Agent.DslAgent.create_session()DataSet.ParserConfig- I'm not sure if the documented parameters are complete.Session.ask()- kwargs specific to agent/chatWhat problem does this PR solve?
Type annotations are really handy for library consumers. They give you handy hints in your IDE and prevent typo bugs. The Python SDK is lacking type annotations, which is annoying at times.
Type of change
Added type annotations.