Skip to content

Commit 8d3f364

Browse files
authored
Pylint Cleanup and Fixes (#163)
* Pylint Run * Remove redundant parens
1 parent 97e4979 commit 8d3f364

File tree

19 files changed

+63
-83
lines changed

19 files changed

+63
-83
lines changed

instana/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def boot_agent():
7878
print("Instana: activated via AutoTrace")
7979
else:
8080
if ("INSTANA_DEBUG" in os.environ) and ("AUTOWRAPT_BOOTSTRAP" not in os.environ):
81-
print("Instana: activated via manual import")
81+
print("Instana: activated via manual import")
8282

8383
# User configurable EUM API key for instana.helpers.eum_snippet()
8484
# pylint: disable=invalid-name

instana/agent.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(self):
5454
self.sensor = Sensor(self)
5555
self.machine = TheMachine(self)
5656

57-
def start(self, e):
57+
def start(self, _):
5858
"""
5959
Starts the agent and required threads
6060
@@ -92,7 +92,7 @@ def extractor(o):
9292

9393
try:
9494
return json.dumps(o, default=extractor, sort_keys=False, separators=(',', ':')).encode()
95-
except:
95+
except Exception:
9696
logger.debug("to_json", exc_info=True)
9797

9898
def is_timed_out(self):
@@ -145,13 +145,13 @@ def is_agent_listening(self, host, port):
145145

146146
server_header = response.headers["Server"]
147147
if server_header == AGENT_HEADER:
148-
logger.debug("Host agent found on %s:%d" % (host, port))
148+
logger.debug("Host agent found on %s:%d", host, port)
149149
rv = True
150150
else:
151-
logger.debug("...something is listening on %s:%d but it's not the Instana Host Agent: %s"
152-
% (host, port, server_header))
151+
logger.debug("...something is listening on %s:%d but it's not the Instana Host Agent: %s",
152+
host, port, server_header)
153153
except (requests.ConnectTimeout, requests.ConnectionError):
154-
logger.debug("Instana Host Agent not found on %s:%d" % (host, port))
154+
logger.debug("Instana Host Agent not found on %s:%d", host, port)
155155
rv = False
156156
finally:
157157
return rv
@@ -162,7 +162,7 @@ def announce(self, discovery):
162162
"""
163163
try:
164164
url = self.__discovery_url()
165-
logger.debug("making announce request to %s" % (url))
165+
logger.debug("making announce request to %s", url)
166166
response = None
167167
response = self.client.put(url,
168168
data=self.to_json(discovery),
@@ -238,7 +238,7 @@ def task_response(self, message_id, data):
238238
response = None
239239
payload = json.dumps(data)
240240

241-
logger.debug("Task response is %s: %s" % (self.__response_url(message_id), payload))
241+
logger.debug("Task response is %s: %s", self.__response_url(message_id), payload)
242242

243243
response = self.client.post(self.__response_url(message_id),
244244
data=payload,

instana/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def upsert_rule_binding(self, rule_binding_config):
246246
return self.put(path, rule_binding_config)
247247

248248
def delete_rule_binding(self, rule_binding_id):
249-
return self.detel('/api/ruleBindings/%s' % rule_binding_id)
249+
return self.delete('/api/ruleBindings/%s' % rule_binding_id)
250250

251251
def rules(self):
252252
return self.get('/api/rules')

instana/flaskana.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def wrapper(wrapped, instance, args, kwargs):
1313
return rv
1414

1515

16-
def hook(module):
16+
def hook(_):
1717
""" Hook method to install the Instana middleware into Flask """
1818
if "INSTANA_DEBUG" in os.environ:
1919
print("==============================================================")

instana/fsm.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(self, agent):
5252
except pkg_resources.DistributionNotFound:
5353
pass
5454

55-
logger.info("Stan is on the scene. Starting Instana instrumentation version: %s" % package_version)
55+
logger.info("Stan is on the scene. Starting Instana instrumentation version: %s", package_version)
5656
logger.debug("initializing fsm")
5757

5858
self.agent = agent
@@ -77,8 +77,8 @@ def __init__(self, agent):
7777

7878
@staticmethod
7979
def print_state_change(e):
80-
logger.debug('========= (%i#%s) FSM event: %s, src: %s, dst: %s ==========' %
81-
(os.getpid(), t.current_thread().name, e.event, e.src, e.dst))
80+
logger.debug('========= (%i#%s) FSM event: %s, src: %s, dst: %s ==========',
81+
os.getpid(), t.current_thread().name, e.event, e.src, e.dst)
8282

8383
def reset(self):
8484
"""
@@ -163,7 +163,7 @@ def announce_sensor(self, e):
163163
if response and (response.status_code is 200) and (len(response.content) > 2):
164164
self.agent.set_from(response.content)
165165
self.fsm.pending()
166-
logger.debug("Announced pid: %s (true pid: %s). Waiting for Agent Ready..." % (str(pid), str(self.agent.from_.pid)))
166+
logger.debug("Announced pid: %s (true pid: %s). Waiting for Agent Ready...", str(pid), str(self.agent.from_.pid))
167167
return True
168168
else:
169169
logger.debug("Cannot announce sensor. Scheduling retry.")
@@ -176,9 +176,9 @@ def schedule_retry(self, fun, e, name):
176176
self.timer.name = name
177177
self.timer.start()
178178

179-
def on_ready(self, e):
180-
logger.info("Host agent available. We're in business. Announced pid: %s (true pid: %s)" %
181-
(str(os.getpid()), str(self.agent.from_.pid)))
179+
def on_ready(self, _):
180+
logger.info("Host agent available. We're in business. Announced pid: %s (true pid: %s)",
181+
str(os.getpid()), str(self.agent.from_.pid))
182182

183183
def __get_real_pid(self):
184184
"""
@@ -200,7 +200,6 @@ def __get_real_pid(self):
200200
pid = int(g.groups()[0])
201201
except Exception:
202202
logger.debug("parsing sched file failed", exc_info=True)
203-
pass
204203

205204
if pid is None:
206205
pid = os.getpid()

instana/helpers.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# eum_snippet(meta=meta_kvs)
1313

1414

15-
def eum_snippet(trace_id=None, eum_api_key=None, meta={}):
15+
def eum_snippet(trace_id=None, eum_api_key=None, meta=None):
1616
"""
1717
Return an EUM snippet for use in views, templates and layouts that reports
1818
client side metrics to Instana that will automagically be linked to the
@@ -30,7 +30,7 @@ def eum_snippet(trace_id=None, eum_api_key=None, meta={}):
3030
eum_src = Template(eum_file.read())
3131

3232
# Prepare the standard required IDs
33-
ids = {}
33+
ids = dict()
3434
ids['meta_kvs'] = ''
3535

3636
parent_span = tracer.active_span
@@ -48,15 +48,17 @@ def eum_snippet(trace_id=None, eum_api_key=None, meta={}):
4848
ids['eum_api_key'] = global_eum_api_key
4949

5050
# Process passed in EUM 'meta' key/values
51-
for key, value in meta.items():
52-
ids['meta_kvs'] += ("'ineum('meta', '%s', '%s');'" % (key, value))
51+
if meta is not None:
52+
for key, value in meta.items():
53+
ids['meta_kvs'] += ("'ineum('meta', '%s', '%s');'" % (key, value))
5354

5455
return eum_src.substitute(ids)
55-
except Exception as e:
56-
logger.debug(e)
56+
except Exception:
57+
logger.debug("eum_snippet: ", exc_info=True)
5758
return ''
5859

59-
def eum_test_snippet(trace_id=None, eum_api_key=None, meta={}):
60+
61+
def eum_test_snippet(trace_id=None, eum_api_key=None, meta=None):
6062
"""
6163
Return an EUM snippet for use in views, templates and layouts that reports
6264
client side metrics to Instana that will automagically be linked to the
@@ -92,10 +94,11 @@ def eum_test_snippet(trace_id=None, eum_api_key=None, meta={}):
9294
ids['eum_api_key'] = global_eum_api_key
9395

9496
# Process passed in EUM 'meta' key/values
95-
for key, value in meta.items():
96-
ids['meta_kvs'] += ("'ineum('meta', '%s', '%s');'" % (key, value))
97+
if meta is not None:
98+
for key, value in meta.items():
99+
ids['meta_kvs'] += ("'ineum('meta', '%s', '%s');'" % (key, value))
97100

98101
return eum_src.substitute(ids)
99-
except Exception as e:
100-
logger.debug(e)
102+
except Exception:
103+
logger.debug("eum_snippet: ", exc_info=True)
101104
return ''

instana/http_propagator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def inject(self, span_context, carrier):
5656
else:
5757
raise Exception("Unsupported carrier type", type(carrier))
5858

59-
except:
59+
except Exception:
6060
logger.debug("inject error:", exc_info=True)
6161

6262
def extract(self, carrier): # noqa
@@ -96,5 +96,5 @@ def extract(self, carrier): # noqa
9696
sampled=True)
9797
return ctx
9898

99-
except Exception as e:
99+
except Exception:
100100
logger.debug("extract error:", exc_info=True)

instana/instrumentation/aiohttp/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async def stan_request_start(session, trace_config_ctx, params):
3232
scope.span.set_tag("http.params", cleaned_qp)
3333
scope.span.set_tag("http.url", parts[0])
3434
scope.span.set_tag('http.method', params.method)
35-
except:
35+
except Exception:
3636
logger.debug("stan_request_start", exc_info=True)
3737

3838
async def stan_request_end(session, trace_config_ctx, params):
@@ -48,7 +48,7 @@ async def stan_request_end(session, trace_config_ctx, params):
4848
scope.span.set_tag("ec", ec + 1)
4949

5050
scope.close()
51-
except:
51+
except Exception:
5252
logger.debug("stan_request_end", exc_info=True)
5353

5454
async def stan_request_exception(session, trace_config_ctx, params):
@@ -58,7 +58,7 @@ async def stan_request_exception(session, trace_config_ctx, params):
5858
scope.span.log_exception(params.exception)
5959
scope.span.set_tag("http.error", str(params.exception))
6060
scope.close()
61-
except:
61+
except Exception:
6262
logger.debug("stan_request_exception", exc_info=True)
6363

6464
@wrapt.patch_function_wrapper('aiohttp.client','ClientSession.__init__')

instana/instrumentation/aiohttp/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async def stan_middleware(request, handler):
5252
response.headers['Server-Timing'] = "intid;desc=%s" % scope.span.context.trace_id
5353

5454
return response
55-
except:
55+
except Exception:
5656
logger.debug("aiohttp stan_middleware", exc_info=True)
5757
finally:
5858
if scope is not None:

instana/instrumentation/django/middleware.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class InstanaMiddleware(MiddlewareMixin):
2222
""" Django Middleware to provide request tracing for Instana """
2323
def __init__(self, get_response=None):
2424
self.get_response = get_response
25-
self
2625

2726
def process_request(self, request):
2827
try:
@@ -118,7 +117,7 @@ def load_middleware_wrapper(wrapped, instance, args, kwargs):
118117

119118
return wrapped(*args, **kwargs)
120119
except Exception:
121-
logger.warn("Instana: Couldn't add InstanaMiddleware to Django: ", exc_info=True)
120+
logger.warn("Instana: Couldn't add InstanaMiddleware to Django: ", exc_info=True)
122121

123122

124123
try:

0 commit comments

Comments
 (0)