Skip to content

Commit 0a5717b

Browse files
committed
added PEP-249 link, changed NoopTelemetryClient implementation
Signed-off-by: Sai Shree Pradhan <saishree.pradhan@databricks.com>
1 parent 44adb21 commit 0a5717b

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/databricks/sql/exc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
logger = logging.getLogger(__name__)
88

99
### PEP-249 Mandated ###
10+
# https://peps.python.org/pep-0249/#exceptions
1011
class Error(Exception):
1112
"""Base class for DB-API2.0 exceptions.
1213
`message`: An optional user-friendly error message. It should be short, actionable and stable

src/databricks/sql/telemetry/telemetry_client.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,27 +104,37 @@ class BaseTelemetryClient(ABC):
104104

105105
@abstractmethod
106106
def export_initial_telemetry_log(self, driver_connection_params, user_agent):
107-
pass
107+
raise NotImplementedError(
108+
"Subclasses must implement export_initial_telemetry_log"
109+
)
108110

109111
@abstractmethod
110112
def export_failure_log(self, error_name, error_message):
111-
pass
113+
raise NotImplementedError("Subclasses must implement export_failure_log")
112114

113115
@abstractmethod
116+
def close(self):
117+
raise NotImplementedError("Subclasses must implement close")
118+
119+
120+
class NoopTelemetryClient(BaseTelemetryClient):
121+
"""
122+
NoopTelemetryClient is a telemetry client that does not send any events to the server.
123+
It is used when telemetry is disabled.
124+
"""
125+
126+
def export_initial_telemetry_log(self, driver_connection_params, user_agent):
127+
pass
128+
129+
def export_failure_log(self, error_name, error_message):
130+
pass
131+
114132
def close(self):
115133
pass
116134

117135

118136
# A single instance of the no-op client that can be reused
119-
NOOP_TELEMETRY_CLIENT = type(
120-
"NoopTelemetryClient",
121-
(BaseTelemetryClient,),
122-
{
123-
"export_initial_telemetry_log": lambda self, *args, **kwargs: None,
124-
"export_failure_log": lambda self, *args, **kwargs: None,
125-
"close": lambda self: None,
126-
},
127-
)()
137+
NOOP_TELEMETRY_CLIENT = NoopTelemetryClient()
128138

129139

130140
class TelemetryClient(BaseTelemetryClient):

0 commit comments

Comments
 (0)