Sourcery refactored master branch - #1
Conversation
| self.name, | ||
| self.parent, | ||
| )) | ||
| return f'{type(self).__name__}(name={self.name}, parent={self.parent})' |
There was a problem hiding this comment.
Function Span.__repr__ refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| i, | ||
| RuntimeContext, | ||
| )) | ||
| print(f'Hello {name} {i} {RuntimeContext}') |
There was a problem hiding this comment.
Function hello refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
|
|
||
| def __repr__(self): | ||
| return ('{}({})'.format(type(self).__name__, self.name)) | ||
| return f'{type(self).__name__}({self.name})' |
There was a problem hiding this comment.
Function Span.__repr__ refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| println('Entering worker[{}]: {}'.format(name, RuntimeContext)) | ||
| println(f'Entering worker[{name}]: {RuntimeContext}') | ||
| RuntimeContext.operation_id = name | ||
| time.sleep(0.01) | ||
| println('Exiting worker[{}]: {}'.format(name, RuntimeContext)) | ||
| println(f'Exiting worker[{name}]: {RuntimeContext}') |
There was a problem hiding this comment.
Function work refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting)
|
|
||
| if __name__ == "__main__": | ||
| println('Main thread: {}'.format(RuntimeContext)) | ||
| println(f'Main thread: {RuntimeContext}') |
There was a problem hiding this comment.
Lines 38-50 refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting)
| if fullpath.endswith('.lock'): | ||
| fullpath = fullpath[: fullpath.rindex('@')] | ||
| fullpath += '@{}.lock'.format(_fmt(timestamp)) | ||
| fullpath += f'@{_fmt(timestamp)}.lock' |
There was a problem hiding this comment.
Function LocalFileBlob.lease refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| interval=self.maintenance_period, | ||
| function=self._maintenance_routine, | ||
| name='{} Storage Worker'.format(source) | ||
| name=f'{source} Storage Worker', |
There was a problem hiding this comment.
Function LocalFileStorage.__init__ refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| pass | ||
| try: | ||
| for blob in self.gets(): | ||
| for _ in self.gets(): |
There was a problem hiding this comment.
Function LocalFileStorage._maintenance_routine refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| if self.options.credential: | ||
| token = self.options.credential.get_token(_MONITOR_OAUTH_SCOPE) | ||
| headers["Authorization"] = "Bearer {}".format(token.token) | ||
| headers["Authorization"] = f"Bearer {token.token}" |
There was a problem hiding this comment.
Function TransportMixin._transmit refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting) - Merge else clause's nested if statement into elif [×3] (
merge-else-if-into-elif) - Use named expression to simplify assignment and conditional (
use-named-expression) - Swap positions of nested conditionals (
swap-nested-ifs)
| if type_name == "success" or type_name == "count": # success, count | ||
| if type_name in ["success", "count"]: # success, count |
There was a problem hiding this comment.
Function _update_requests_map refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| opencensus_version, | ||
| ext_version, | ||
| ), | ||
| 'ai.internal.sdkVersion': f'py{platform.python_version()}:oc{opencensus_version}:ext{ext_version}', |
There was a problem hiding this comment.
Lines 33-37 refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| super(Worker, self).__init__( | ||
| name='{} Worker'.format(type(dst).__name__) | ||
| ) | ||
| super(Worker, self).__init__(name=f'{type(dst).__name__} Worker') |
There was a problem hiding this comment.
Function Worker.__init__ refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| level = 0 | ||
| has_full_stack = False | ||
| exc_type = "N/A" | ||
| message = self.format(record) | ||
| if tb is not None: | ||
| has_full_stack = True | ||
| for fileName, line, method, _text in traceback.extract_tb(tb): | ||
| callstack.append({ | ||
| callstack.extend( | ||
| { | ||
| 'level': level, | ||
| 'method': method, | ||
| 'fileName': fileName, | ||
| 'line': line, | ||
| }) | ||
| level += 1 | ||
| } | ||
| for level, (fileName, line, method, _text) in enumerate( | ||
| traceback.extract_tb(tb) | ||
| ) | ||
| ) | ||
| callstack.reverse() | ||
| elif record.message: | ||
| message = record.message | ||
|
|
||
| if exctype is not None: | ||
| exc_type = exctype.__name__ | ||
|
|
||
| exc_type = exctype.__name__ if exctype is not None else "N/A" |
There was a problem hiding this comment.
Function AzureLogHandler.log_record_to_envelope refactored with the following changes:
- Move assignments closer to their usage (
move-assign) - Move assignment closer to its usage within a block (
move-assign-in-block) - Replace manual loop counter with call to enumerate (
convert-to-enumerate) - Replace a for append loop with list extend (
for-append-to-extend) - Move setting of default value for variable into
elsebranch (introduce-default-else) - Replace if statement with if expression (
assign-if-exp)
| envelope.tags['ai.operation.parentId'] = '|{}.{}.'.format( | ||
| envelope.tags['ai.operation.id'], | ||
| getattr(record, 'spanId', '0000000000000000'), | ||
| ) | ||
| envelope.tags[ | ||
| 'ai.operation.parentId' | ||
| ] = f"|{envelope.tags['ai.operation.id']}.{getattr(record, 'spanId', '0000000000000000')}." |
There was a problem hiding this comment.
Function create_envelope refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| if self.exporter_thread: | ||
| # flush if metrics exporter is not for stats | ||
| if not self._is_stats: | ||
| self.exporter_thread.close() | ||
| else: | ||
| if self._is_stats: | ||
| self.exporter_thread.cancel() |
There was a problem hiding this comment.
Function MetricsExporter.shutdown refactored with the following changes:
- Swap positions of nested conditionals [×2] (
swap-nested-ifs) - Hoist nested repeated code outside conditional statements [×2] (
hoist-similar-statement-from-if) - Swap if/else branches (
swap-if-else-branches)
This removes the following comments ( why? ):
# flush if metrics exporter is not for stats
| envelope.tags['ai.operation.parentId'] = '{}'.format( | ||
| sd.parent_span_id, | ||
| ) | ||
| envelope.tags['ai.operation.parentId'] = f'{sd.parent_span_id}' |
There was a problem hiding this comment.
Function AzureExporter.span_data_to_envelope refactored with the following changes:
- Replace call to format with f-string [×3] (
use-fstring-for-formatting) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation) - Convert for loop into list comprehension (
list-comprehension)
This removes the following comments ( why? ):
# TODO
# Modify based off attributes or status
|
|
||
| mm = metric.Metric(descriptor=desc, time_series=ts) | ||
| return mm | ||
| return metric.Metric(descriptor=desc, time_series=ts) |
There was a problem hiding this comment.
Function create_metric refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| mm = metric.Metric(descriptor=desc, time_series=ts) | ||
| return mm | ||
| return metric.Metric(descriptor=desc, time_series=ts) |
There was a problem hiding this comment.
Function create_metric_ts refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| mm = metric.Metric(descriptor=desc, time_series=ts) | ||
| return mm | ||
| return metric.Metric(descriptor=desc, time_series=ts) |
There was a problem hiding this comment.
Function create_stats_metric refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| _requests_map.clear() | ||
| _requests_map['failure'] = {} | ||
| _requests_map['failure'][400] = 10 | ||
| _requests_map['failure'] = {400: 10} |
There was a problem hiding this comment.
Function TestStatsbeatMetrics.test_get_failure_count_value refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign)
| _requests_map['retry'] = {} | ||
| _requests_map['retry'][401] = 10 | ||
| _requests_map['retry'] = {401: 10} |
There was a problem hiding this comment.
Function TestStatsbeatMetrics.test_get_retry_count_value refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign)
| _requests_map['throttle'] = {} | ||
| _requests_map['throttle'][402] = 10 | ||
| _requests_map['throttle'] = {402: 10} |
There was a problem hiding this comment.
Function TestStatsbeatMetrics.test_get_throttle_count_value refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign)
| _requests_map['exception'] = {} | ||
| _requests_map['exception']['Timeout'] = 10 | ||
| _requests_map['exception'] = {'Timeout': 10} |
There was a problem hiding this comment.
Function TestStatsbeatMetrics.test_get_exception_count_value refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign)
| _vm_data = {} | ||
| _vm_data["vmId"] = "123" | ||
| _vm_data["subscriptionId"] = "sub123" | ||
| _vm_data["osType"] = "linux" | ||
| _vm_data = {"vmId": "123", "subscriptionId": "sub123", "osType": "linux"} |
There was a problem hiding this comment.
Function TestStatsbeatMetrics.test_get_attach_metric_vm refactored with the following changes:
- Merge dictionary assignment with declaration [×3] (
merge-dict-assign)
| _vm_data = {} | ||
| _vm_data["vmId"] = "123" | ||
| _vm_data["subscriptionId"] = "sub123" | ||
| _vm_data["osType"] = None | ||
| _vm_data = {"vmId": "123", "subscriptionId": "sub123", "osType": None} |
There was a problem hiding this comment.
Function TestStatsbeatMetrics.test_get_attach_metric_vm_no_os refactored with the following changes:
- Merge dictionary assignment with declaration [×3] (
merge-dict-assign)
|
|
||
| span = tracer.start_span() | ||
| span.name = '{}.query'.format(vendor) | ||
| span.name = f'{vendor}.query' |
There was a problem hiding this comment.
Function _trace_db_call refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| trace_id = '2dd43a1d6b2549c6bc2a1a54c2fc0b05' | ||
| span_id = '6e0c63257de34c92' | ||
| django_trace_id = '00-{}-{}-00'.format(trace_id, span_id) | ||
| django_trace_id = f'00-{trace_id}-{span_id}-00' |
There was a problem hiding this comment.
Function TestOpencensusMiddleware.test_process_request refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| trace_id = '2dd43a1d6b2549c6bc2a1a54c2fc0b05' | ||
| span_id = '6e0c63257de34c92' | ||
| django_trace_id = '00-{}-{}-00'.format(trace_id, span_id) | ||
| django_trace_id = f'00-{trace_id}-{span_id}-00' |
There was a problem hiding this comment.
Function TestOpencensusMiddleware.test_process_response refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| trace_id = '2dd43a1d6b2549c6bc2a1a54c2fc0b05' | ||
| span_id = '6e0c63257de34c92' | ||
| django_trace_id = '00-{}-{}-00'.format(trace_id, span_id) | ||
| django_trace_id = f'00-{trace_id}-{span_id}-00' |
There was a problem hiding this comment.
Function TestOpencensusMiddleware.test_process_response_unfinished_child_span refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| trace_id = '2dd43a1d6b2549c6bc2a1a54c2fc0b05' | ||
| span_id = '6e0c63257de34c92' | ||
| django_trace_id = '00-{}-{}-00'.format(trace_id, span_id) | ||
| django_trace_id = f'00-{trace_id}-{span_id}-00' |
There was a problem hiding this comment.
Function TestOpencensusMiddleware.test_process_exception refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
Branch
masterrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run:Help us improve this pull request!