Skip to content

Commit ec19c8b

Browse files
committed
pylint fixes
1 parent eb7b606 commit ec19c8b

6 files changed

Lines changed: 23 additions & 20 deletions

File tree

src/telemetric/ga4/analytics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ def track_event(
5858
}
5959

6060
url = f"{self.proxy_url}/track"
61-
_log.debug(f"POST request to: {url}")
61+
_log.debug("POST request to: %s", url)
6262
_log.debug(payload)
6363

6464
try: # noqa: SIM105
6565
requests.post(f"{self.proxy_url}/track", json=payload, timeout=2)
66-
except Exception:
66+
except (requests.RequestException, OSError):
6767
pass

src/telemetric/ga4/ga4_proxy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async def track_event(request: Request): # type: ignore[no-untyped-def]
9999
{"status": "error", "message": "GA4 request failed"}, status_code=502
100100
)
101101

102-
except Exception as e:
102+
except (requests.RequestException, ValueError, KeyError) as e:
103103
return JSONResponse({"status": "error", "message": str(e)}, status_code=500)
104104

105105

src/telemetric/ga4/stats_uploader.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ def upload_function_stats( # type: ignore[no-untyped-def]
4343
return False
4444

4545
# Get function counts: (total_calls, error_calls, invalid_args)
46-
counts = wrapped_func._get_counts()
46+
counts = wrapped_func._get_counts() # pylint: disable=protected-access
4747
total_calls, error_calls, invalid_args = counts
4848

4949
# Skip functions that haven't been called
5050
if total_calls == 0:
5151
return True
5252

5353
# Get parameter statistics
54-
param_stats = wrapped_func._get_param_stats()
54+
param_stats = wrapped_func._get_param_stats() # pylint: disable=protected-access
5555

5656
# Build event parameters
5757
event_params = {
@@ -122,7 +122,7 @@ def upload_all_stats(
122122
skipped = 0
123123

124124
for wrapped_func in _wrapped:
125-
counts = wrapped_func._get_counts()
125+
counts = wrapped_func._get_counts() # pylint: disable=protected-access
126126
total_calls = counts[0]
127127

128128
if skip_uncalled and total_calls == 0:
@@ -135,9 +135,9 @@ def upload_all_stats(
135135
# Upload summary statistics
136136
summary_params = {
137137
"total_wrapped_functions": len(_wrapped),
138-
"functions_called": sum(1 for f in _wrapped if f._get_counts()[0] > 0),
139-
"total_function_calls": sum(f._get_counts()[0] for f in _wrapped),
140-
"total_errors": sum(f._get_counts()[1] for f in _wrapped),
138+
"functions_called": sum(1 for f in _wrapped if f._get_counts()[0] > 0), # pylint: disable=protected-access
139+
"total_function_calls": sum(f._get_counts()[0] for f in _wrapped), # pylint: disable=protected-access
140+
"total_errors": sum(f._get_counts()[1] for f in _wrapped), # pylint: disable=protected-access
141141
}
142142

143143
if package_name:

src/telemetric/path_finder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
class TelemetryMetaFinder(MetaPathFinder):
15+
"""MetaPathFinder implementation that overrides spec loaders with telemetry-enabled loaders."""
1516
def __init__(self, module_names: list[str], *args, **kwargs) -> None: # type: ignore[no-untyped-def]
1617
"""MetaPathFinder implementation that overrides a spec loader
1718
of type SourceFileLoader with a TelemetrySpanLoader.
@@ -42,6 +43,7 @@ def find_spec(self, fullname: str, path, target=None): # type: ignore[no-untype
4243

4344

4445
class TelemetrySpanSourceFileLoader(SourceFileLoader):
46+
"""SourceFileLoader that automatically adds telemetry decorators to functions and methods."""
4547
def exec_module(self, module) -> None: # type: ignore[no-untyped-def]
4648
super().exec_module(module)
4749
functions = inspect.getmembers(module, predicate=inspect.isfunction)

src/telemetric/span.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ def span(func): # type: ignore[no-untyped-def]
3030

3131
@wraps(func)
3232
def span_wrapper(*args, **kwargs): # type: ignore[no-untyped-def]
33-
with tracer.start_as_current_span(func_name) as span:
34-
span.set_attribute("num_args", len(args))
35-
span.set_attribute("num_kwargs", len(kwargs))
33+
with tracer.start_as_current_span(func_name) as current_span:
34+
current_span.set_attribute("num_args", len(args))
35+
current_span.set_attribute("num_kwargs", len(kwargs))
3636
for n, arg in enumerate(args):
37-
span.set_attribute(f"args.{n}", _serialize(arg)) # type: ignore[no-untyped-call]
37+
current_span.set_attribute(f"args.{n}", _serialize(arg)) # type: ignore[no-untyped-call]
3838
for k, v in kwargs.items():
39-
span.set_attribute(f"kwargs.{k}", v)
40-
span.set_status(trace.StatusCode.OK)
39+
current_span.set_attribute(f"kwargs.{k}", v)
40+
current_span.set_status(trace.StatusCode.OK)
4141
return func(*args, **kwargs)
4242

4343
return span_wrapper

src/telemetric/statswrapper/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright (c) 2025 Scientific Python. All rights reserved.
2+
# pylint: disable=import-error,no-name-in-module
23
from __future__ import annotations
34

45
import functools
@@ -14,17 +15,17 @@
1415
_wrapped: list[_StatsWrapper] = []
1516

1617

17-
def print_all_stats(skip_uncalled: bool = True) -> None: # noqa: ARG001
18+
def print_all_stats(skip_uncalled: bool = True) -> None: # noqa: ARG001 # pylint: disable=unused-argument
1819
print() # noqa: T201
1920
print("Statistics for argument usage of wrapped functions") # noqa: T201
2021
print("--------------------------------------------------") # noqa: T201
21-
sorted_w = sorted(_wrapped, key=lambda x: x._get_counts()[0], reverse=True)
22+
sorted_w = sorted(_wrapped, key=lambda x: x._get_counts()[0], reverse=True) # pylint: disable=protected-access
2223
for func in sorted_w:
23-
counts = func._get_counts()
24+
counts = func._get_counts() # pylint: disable=protected-access
2425
if counts[0] == 0:
2526
continue
2627
counts = f"{counts[0]},{counts[1]},{counts[2]}"
27-
stats = func._get_param_stats()
28+
stats = func._get_param_stats() # pylint: disable=protected-access
2829
argcounts = []
2930
for name, n_uses, _, _ in stats:
3031
if name is None:
@@ -146,7 +147,7 @@ def stats_deco_auto(func, /, *, track_positional_use: bool = False): # type: ig
146147
pass
147148

148149
new = stats_wrapper(func, *args, **kwargs)
149-
new._set_npos(len(args) + positional_kws)
150+
new._set_npos(len(args) + positional_kws) # pylint: disable=protected-access
150151

151152
functools.update_wrapper(new, func)
152153
if hasattr(func, "__code__"):

0 commit comments

Comments
 (0)