Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions deepgram/clients/agent/v1/websocket/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
# SPDX-License-Identifier: MIT

from typing import List, Optional, Union, Any, Tuple
from typing import List, Optional, Union, Any, Tuple, Dict
import logging

from dataclasses import dataclass, field
Expand Down Expand Up @@ -77,18 +77,34 @@ class Endpoint(BaseResponse):

method: Optional[str] = field(default="POST")
url: str = field(default="")
headers: Optional[List[Header]] = field(
headers: Optional[Union[Dict[str, str], List[Header]]] = field(
default=None, metadata=dataclass_config(exclude=lambda f: f is None)
)

def __getitem__(self, key):
_dict = self.to_dict()
if "headers" in _dict:
_dict["headers"] = [
Header.from_dict(headers) for headers in _dict["headers"]
]
if isinstance(self.headers, list):
_dict["headers"] = [
Header.from_dict(headers) if isinstance(headers, dict) else headers
for headers in _dict["headers"]
]
elif isinstance(self.headers, dict):
_dict["headers"] = self.headers
return _dict[key]

def to_dict(self) -> dict:
"""
Convert the endpoint to a dictionary, properly handling headers.
"""
result = super().to_dict()
if self.headers:
if isinstance(self.headers, dict):
result["headers"] = self.headers
else:
result["headers"] = {h.key: h.value for h in self.headers}
return result

Comment on lines +96 to +107
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Fix the method signature to match parent class

The to_dict method implementation has a signature that's incompatible with the parent class, which is causing pipeline failures.

-    def to_dict(self) -> dict:
+    def to_dict(self, encode_json=False) -> dict:

The error messages from the CI pipeline indicate:

  • mypy error: Signature incompatible with supertype 'DataClassJsonMixin'
  • pylint warning: Number of parameters was 2 in 'DataClassJsonMixin.to_dict' and is now 1 in overriding method

The method needs to maintain the same signature as the parent class while implementing the additional logic to handle the headers properly.


🏁 Script executed:

#!/bin/bash
# Check the signature of DataClassJsonMixin.to_dict
rg -A 5 "def to_dict" --glob="*.py" | grep -A 5 "class.*DataClassJsonMixin"

Length of output: 77


🏁 Script executed:

#!/bin/bash
# Verify the signature of DataClassJsonMixin.to_dict from the dataclasses-json library
pip install dataclasses-json
python3 - << 'EOF'
from dataclasses_json import DataClassJsonMixin
import inspect
src = inspect.getsource(DataClassJsonMixin.to_dict)
sig = inspect.signature(DataClassJsonMixin.to_dict)
print("Source of DataClassJsonMixin.to_dict:")
print(src)
print("Signature of DataClassJsonMixin.to_dict:", sig)
EOF

Length of output: 1375


Fix to_dict signature to match DataClassJsonMixin
The parent class defines to_dict(self, encode_json=False), so your override must include the same parameter and pass it through to super(). Without this change, mypy and pylint will continue to report an incompatible signature.

• File: deepgram/clients/agent/v1/websocket/options.py (lines 96–107)
• Update method signature and the call to super().to_dict

-    def to_dict(self) -> dict:
+    def to_dict(self, encode_json=False) -> dict:
         """
         Convert the endpoint to a dictionary, properly handling headers.
         """
-        result = super().to_dict()
+        result = super().to_dict(encode_json=encode_json)
         if self.headers:
             if isinstance(self.headers, dict):
                 result["headers"] = self.headers
             else:
                 result["headers"] = {h.key: h.value for h in self.headers}
         return result

— Signature verified via inspect.signature(DataClassJsonMixin.to_dict) returning (self, encode_json=False)

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def to_dict(self) -> dict:
"""
Convert the endpoint to a dictionary, properly handling headers.
"""
result = super().to_dict()
if self.headers:
if isinstance(self.headers, dict):
result["headers"] = self.headers
else:
result["headers"] = {h.key: h.value for h in self.headers}
return result
def to_dict(self, encode_json=False) -> dict:
"""
Convert the endpoint to a dictionary, properly handling headers.
"""
result = super().to_dict(encode_json=encode_json)
if self.headers:
if isinstance(self.headers, dict):
result["headers"] = self.headers
else:
result["headers"] = {h.key: h.value for h in self.headers}
return result
🧰 Tools
🪛 GitHub Actions: Check - static

[error] 96-96: mypy type checking error: Signature of 'to_dict' incompatible with supertype 'DataClassJsonMixin'. Expected 'to_dict(self, encode_json: Any = ...) -> dict[str, dict[Any, Any] | list[Any] | str | int | float | bool | None]', but found 'to_dict(self) -> dict[Any, Any]'.

🪛 GitHub Actions: Check - lint

[warning] 96-96: pylint W0221: Number of parameters was 2 in 'DataClassJsonMixin.to_dict' and is now 1 in overriding 'Endpoint.to_dict' method (arguments-differ)

🤖 Prompt for AI Agents (early access)
In deepgram/clients/agent/v1/websocket/options.py lines 96 to 107, the to_dict
method signature does not match the parent class DataClassJsonMixin's to_dict,
which expects a parameter encode_json with a default value. Update the method
signature to include encode_json=False and pass this parameter when calling
super().to_dict to ensure compatibility and fix the mypy and pylint errors.


@dataclass
class Function(BaseResponse):
Expand Down
Loading