-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery Starbot ⭐ refactored AlfiyaZi/jaeger-client-python #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| self._processMap = {} | ||
| self._processMap["startTrace"] = Processor.process_startTrace | ||
| self._processMap["joinTrace"] = Processor.process_joinTrace | ||
| self._processMap = { | ||
| "startTrace": Processor.process_startTrace, | ||
| "joinTrace": Processor.process_joinTrace, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Processor.__init__ refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign)
| if name not in self._processMap: | ||
| iprot.skip(TType.STRUCT) | ||
| iprot.readMessageEnd() | ||
| x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name)) | ||
| oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid) | ||
| x.write(oprot) | ||
| oprot.writeMessageEnd() | ||
| oprot.trans.flush() | ||
| return | ||
| else: | ||
| if name in self._processMap: | ||
| return self._processMap[name](self, seqid, iprot, oprot) | ||
|
|
||
| iprot.skip(TType.STRUCT) | ||
| iprot.readMessageEnd() | ||
| x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name)) | ||
| oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid) | ||
| x.write(oprot) | ||
| oprot.writeMessageEnd() | ||
| oprot.trans.flush() | ||
| return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Processor.process refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if fid == 1: | ||
| if ftype == TType.STRUCT: | ||
| self.request = StartTraceRequest() | ||
| self.request.read(iprot) | ||
| else: | ||
| iprot.skip(ftype) | ||
| if fid == 1 and ftype == TType.STRUCT: | ||
| self.request = StartTraceRequest() | ||
| self.request.read(iprot) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function startTrace_args.read refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks)
| iprot.skip(ftype) | ||
| if fid == 0 and ftype == TType.STRUCT: | ||
| self.success = TraceResponse() | ||
| self.success.read(iprot) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function startTrace_result.read refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks)
| if fid == 1: | ||
| if ftype == TType.STRUCT: | ||
| self.request = JoinTraceRequest() | ||
| self.request.read(iprot) | ||
| else: | ||
| iprot.skip(ftype) | ||
| if fid == 1 and ftype == TType.STRUCT: | ||
| self.request = JoinTraceRequest() | ||
| self.request.read(iprot) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function joinTrace_args.read refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks)
| for key in tags.keys(): | ||
| tag_name_list.append(key) | ||
| return tag_name_list | ||
| return [key for key in tags.keys()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function PrometheusMetricsFactory._get_tag_name_list refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| self._processMap = {} | ||
| self._processMap["emitZipkinBatch"] = Processor.process_emitZipkinBatch | ||
| self._processMap["emitBatch"] = Processor.process_emitBatch | ||
| self._processMap = { | ||
| "emitZipkinBatch": Processor.process_emitZipkinBatch, | ||
| "emitBatch": Processor.process_emitBatch, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Processor.__init__ refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign)
| if name not in self._processMap: | ||
| iprot.skip(TType.STRUCT) | ||
| iprot.readMessageEnd() | ||
| x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name)) | ||
| oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid) | ||
| x.write(oprot) | ||
| oprot.writeMessageEnd() | ||
| oprot.trans.flush() | ||
| return | ||
| else: | ||
| if name in self._processMap: | ||
| return self._processMap[name](self, seqid, iprot, oprot) | ||
|
|
||
| iprot.skip(TType.STRUCT) | ||
| iprot.readMessageEnd() | ||
| x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name)) | ||
| oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid) | ||
| x.write(oprot) | ||
| oprot.writeMessageEnd() | ||
| oprot.trans.flush() | ||
| return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Processor.process refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if fid == 1: | ||
| if ftype == TType.LIST: | ||
| self.spans = [] | ||
| (_etype3, _size0) = iprot.readListBegin() | ||
| for _i4 in xrange(_size0): | ||
| _elem5 = zipkincore.ttypes.Span() | ||
| _elem5.read(iprot) | ||
| self.spans.append(_elem5) | ||
| iprot.readListEnd() | ||
| else: | ||
| iprot.skip(ftype) | ||
| if fid == 1 and ftype == TType.LIST: | ||
| self.spans = [] | ||
| (_etype3, _size0) = iprot.readListBegin() | ||
| for _i4 in xrange(_size0): | ||
| _elem5 = zipkincore.ttypes.Span() | ||
| _elem5.read(iprot) | ||
| self.spans.append(_elem5) | ||
| iprot.readListEnd() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function emitZipkinBatch_args.read refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks)
| iprot.skip(ftype) | ||
| if fid == 1 and ftype == TType.STRUCT: | ||
| self.batch = jaeger.ttypes.Batch() | ||
| self.batch.read(iprot) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function emitBatch_args.read refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks)
| self._handler = handler | ||
| self._processMap = {} | ||
| self._processMap["submitBatches"] = Processor.process_submitBatches | ||
| self._processMap = {"submitBatches": Processor.process_submitBatches} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Processor.__init__ refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign)
| if name not in self._processMap: | ||
| iprot.skip(TType.STRUCT) | ||
| iprot.readMessageEnd() | ||
| x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name)) | ||
| oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid) | ||
| x.write(oprot) | ||
| oprot.writeMessageEnd() | ||
| oprot.trans.flush() | ||
| return | ||
| else: | ||
| if name in self._processMap: | ||
| return self._processMap[name](self, seqid, iprot, oprot) | ||
|
|
||
| iprot.skip(TType.STRUCT) | ||
| iprot.readMessageEnd() | ||
| x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name)) | ||
| oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid) | ||
| x.write(oprot) | ||
| oprot.writeMessageEnd() | ||
| oprot.trans.flush() | ||
| return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Processor.process refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if fid == 1: | ||
| if ftype == TType.LIST: | ||
| self.batches = [] | ||
| (_etype45, _size42) = iprot.readListBegin() | ||
| for _i46 in xrange(_size42): | ||
| _elem47 = Batch() | ||
| _elem47.read(iprot) | ||
| self.batches.append(_elem47) | ||
| iprot.readListEnd() | ||
| else: | ||
| iprot.skip(ftype) | ||
| if fid == 1 and ftype == TType.LIST: | ||
| self.batches = [] | ||
| (_etype45, _size42) = iprot.readListBegin() | ||
| for _i46 in xrange(_size42): | ||
| _elem47 = Batch() | ||
| _elem47.read(iprot) | ||
| self.batches.append(_elem47) | ||
| iprot.readListEnd() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function submitBatches_args.read refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks)
| if fid == 0: | ||
| if ftype == TType.LIST: | ||
| self.success = [] | ||
| (_etype52, _size49) = iprot.readListBegin() | ||
| for _i53 in xrange(_size49): | ||
| _elem54 = BatchSubmitResponse() | ||
| _elem54.read(iprot) | ||
| self.success.append(_elem54) | ||
| iprot.readListEnd() | ||
| else: | ||
| iprot.skip(ftype) | ||
| if fid == 0 and ftype == TType.LIST: | ||
| self.success = [] | ||
| (_etype52, _size49) = iprot.readListBegin() | ||
| for _i53 in xrange(_size49): | ||
| _elem54 = BatchSubmitResponse() | ||
| _elem54.read(iprot) | ||
| self.success.append(_elem54) | ||
| iprot.readListEnd() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function submitBatches_result.read refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks)
| if fid == 1: | ||
| if ftype == TType.I64: | ||
| self.timestamp = iprot.readI64() | ||
| else: | ||
| iprot.skip(ftype) | ||
| elif fid == 2: | ||
| if ftype == TType.LIST: | ||
| self.fields = [] | ||
| (_etype3, _size0) = iprot.readListBegin() | ||
| for _i4 in xrange(_size0): | ||
| _elem5 = Tag() | ||
| _elem5.read(iprot) | ||
| self.fields.append(_elem5) | ||
| iprot.readListEnd() | ||
| else: | ||
| iprot.skip(ftype) | ||
| else: | ||
| if fid == 1 and ftype == TType.I64: | ||
| self.timestamp = iprot.readI64() | ||
| elif ftype != TType.LIST or fid != 2: | ||
| iprot.skip(ftype) | ||
| else: | ||
| self.fields = [] | ||
| (_etype3, _size0) = iprot.readListBegin() | ||
| for _i4 in xrange(_size0): | ||
| _elem5 = Tag() | ||
| _elem5.read(iprot) | ||
| self.fields.append(_elem5) | ||
| iprot.readListEnd() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Log.read refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks) - Remove redundant conditional (
remove-redundant-if)
| self._handler = handler | ||
| self._processMap = {} | ||
| self._processMap["submitZipkinBatch"] = Processor.process_submitZipkinBatch | ||
| self._processMap = {"submitZipkinBatch": Processor.process_submitZipkinBatch} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Processor.__init__ refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign)
| if name not in self._processMap: | ||
| iprot.skip(TType.STRUCT) | ||
| iprot.readMessageEnd() | ||
| x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name)) | ||
| oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid) | ||
| x.write(oprot) | ||
| oprot.writeMessageEnd() | ||
| oprot.trans.flush() | ||
| return | ||
| else: | ||
| if name in self._processMap: | ||
| return self._processMap[name](self, seqid, iprot, oprot) | ||
|
|
||
| iprot.skip(TType.STRUCT) | ||
| iprot.readMessageEnd() | ||
| x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name)) | ||
| oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid) | ||
| x.write(oprot) | ||
| oprot.writeMessageEnd() | ||
| oprot.trans.flush() | ||
| return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Processor.process refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if fid == 1: | ||
| if ftype == TType.LIST: | ||
| self.spans = [] | ||
| (_etype17, _size14) = iprot.readListBegin() | ||
| for _i18 in xrange(_size14): | ||
| _elem19 = Span() | ||
| _elem19.read(iprot) | ||
| self.spans.append(_elem19) | ||
| iprot.readListEnd() | ||
| else: | ||
| iprot.skip(ftype) | ||
| if fid == 1 and ftype == TType.LIST: | ||
| self.spans = [] | ||
| (_etype17, _size14) = iprot.readListBegin() | ||
| for _i18 in xrange(_size14): | ||
| _elem19 = Span() | ||
| _elem19.read(iprot) | ||
| self.spans.append(_elem19) | ||
| iprot.readListEnd() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function submitZipkinBatch_args.read refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks)
| if fid == 0: | ||
| if ftype == TType.LIST: | ||
| self.success = [] | ||
| (_etype24, _size21) = iprot.readListBegin() | ||
| for _i25 in xrange(_size21): | ||
| _elem26 = Response() | ||
| _elem26.read(iprot) | ||
| self.success.append(_elem26) | ||
| iprot.readListEnd() | ||
| else: | ||
| iprot.skip(ftype) | ||
| if fid == 0 and ftype == TType.LIST: | ||
| self.success = [] | ||
| (_etype24, _size21) = iprot.readListBegin() | ||
| for _i25 in xrange(_size21): | ||
| _elem26 = Response() | ||
| _elem26.read(iprot) | ||
| self.success.append(_elem26) | ||
| iprot.readListEnd() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function submitZipkinBatch_result.read refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks)
| if fid == 1: | ||
| if ftype == TType.BOOL: | ||
| self.ok = iprot.readBool() | ||
| else: | ||
| iprot.skip(ftype) | ||
| if fid == 1 and ftype == TType.BOOL: | ||
| self.ok = iprot.readBool() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Response.read refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks)
| good_headers_bad_values = { | ||
| 'Trace-ID': '100:7f:0:1xxx', | ||
| 'trace-attr-Kiff': 'Amy' | ||
| } | ||
| with self.assertRaises(SpanContextCorruptedException): | ||
| good_headers_bad_values = { | ||
| 'Trace-ID': '100:7f:0:1xxx', | ||
| 'trace-attr-Kiff': 'Amy' | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function TestCodecs.test_context_from_bad_readable_headers refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| codec = tracer.codecs[Format.HTTP_HEADERS] | ||
| headers = { | ||
| 'Trace-ID': '100%3A7f:0:1', | ||
| 'trace-attr-Kiff': 'Amy%20Wang', | ||
| 'trace-atTR-HERMES': 'LaBarbara%20Hermes' | ||
| } | ||
| else: | ||
| codec = tracer.codecs[Format.HTTP_HEADERS] | ||
| headers = { | ||
| 'Trace-ID': '100:7f:0:1', | ||
| 'trace-attr-Kiff': 'Amy Wang', | ||
| 'trace-atTR-HERMES': 'LaBarbara Hermes' | ||
| } | ||
| codec = tracer.codecs[Format.HTTP_HEADERS] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function TestCodecs.test_context_from_readable_headers refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if)
| carrier = dict() | ||
| carrier = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function test_inject_with_128bit_trace_id refactored with the following changes:
- Replace dict() with {} (
dict-literal)
| level3 = dict() | ||
| level3['serviceName'] = 'python' | ||
| level3['serverRole'] = 's3' | ||
| level3['transport'] = s3_transport | ||
| level3['host'] = 'localhost' | ||
| level3['port'] = str(http_port) if s3_transport == 'HTTP' else tchannel_port | ||
|
|
||
| level2 = dict() | ||
| level2['serviceName'] = 'python' | ||
| level2['serverRole'] = 's2' | ||
| level2['transport'] = s2_transport | ||
| level2['host'] = 'localhost' | ||
| level2['port'] = str(http_port) if s2_transport == 'HTTP' else tchannel_port | ||
| level2['downstream'] = level3 | ||
|
|
||
| level1 = dict() | ||
| level1['baggage'] = 'Zoidberg' | ||
| level1['serverRole'] = 's1' | ||
| level1['sampled'] = sampled | ||
| level1['downstream'] = level2 | ||
| level3 = { | ||
| 'serviceName': 'python', | ||
| 'serverRole': 's3', | ||
| 'transport': s3_transport, | ||
| 'host': 'localhost', | ||
| 'port': str(http_port) if s3_transport == 'HTTP' else tchannel_port, | ||
| } | ||
|
|
||
| level2 = { | ||
| 'serviceName': 'python', | ||
| 'serverRole': 's2', | ||
| 'transport': s2_transport, | ||
| 'host': 'localhost', | ||
| 'port': str(http_port) if s2_transport == 'HTTP' else tchannel_port, | ||
| 'downstream': level3, | ||
| } | ||
|
|
||
| level1 = { | ||
| 'baggage': 'Zoidberg', | ||
| 'serverRole': 's1', | ||
| 'sampled': sampled, | ||
| 'downstream': level2, | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function test_trace_propagation refactored with the following changes:
- Replace dict() with {} (
dict-literal) - Merge dictionary assignment with declaration (
merge-dict-assign)
| payload = dict() | ||
| payload['operation'] = 'Zoidberg' | ||
| payload['count'] = 2 | ||
| payload['tags'] = {'key': 'value'} | ||
| payload = {'operation': 'Zoidberg', 'count': 2, 'tags': {'key': 'value'}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function test_endtoend_handler refactored with the following changes:
- Replace dict() with {} (
dict-literal) - Merge dictionary assignment with declaration (
merge-dict-assign)
| sampler.rate_limiter.last_tick = ts | ||
| with mock.patch('jaeger_client.rate_limiter.RateLimiter.timestamp') \ | ||
| as mock_time: | ||
| as mock_time: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function test_rate_limiting_sampler refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range) - Replace unused for index with underscore (
for-index-underscore)
| args=args if args else [], | ||
| args=args or [], | ||
| expected=expected, | ||
| kwargs=kwargs if kwargs else {}, | ||
| kwargs=kwargs or {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function test_span_logging.test refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity)
| span = 'span' | ||
| carrier = {} | ||
| with pytest.raises(ValueError): | ||
| span = 'span' | ||
| carrier = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function test_serialization_error refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| codecs = { | ||
| 'extra_codec': 'codec_placeholder', | ||
| Format.BINARY: 'overridden_binary_codec' | ||
|
|
||
| } | ||
| with mock.patch('socket.gethostname', return_value='dream-host.com'): | ||
| codecs = { | ||
| 'extra_codec': 'codec_placeholder', | ||
| Format.BINARY: 'overridden_binary_codec' | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function test_tracer_override_codecs refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
|
|
||
| def _generate_spans(tracer, iterations=1000, sleep=None): | ||
| for i in range(0, iterations): | ||
| for _ in range(iterations): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _generate_spans refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range) - Replace unused for index with underscore (
for-index-underscore)
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run: