Skip to content

Commit d20f4b3

Browse files
adamantikeowais
andauthored
Refactor code using pyupgrade for Python 3.6 (#2238)
* Refactor code using pyupgrade for Python 3.6 This diff is the result of applying the following command to the project: ```shell find . -type f -name "*.py" -exec pyupgrade --py36-plus '{}' + ``` * Revert changes in autogenerated files * Remove changes on autogenerated files Co-authored-by: Owais Lone <[email protected]>
1 parent 64e884a commit d20f4b3

File tree

38 files changed

+38
-86
lines changed

38 files changed

+38
-86
lines changed

docs/examples/basic_context/implicit_context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
with tracer.start_span(name="root span") as root_span:
2222
ctx = baggage.set_baggage("foo", "bar")
2323

24-
print("Global context baggage: {}".format(baggage.get_all()))
25-
print("Span context baggage: {}".format(baggage.get_all(context=ctx)))
24+
print(f"Global context baggage: {baggage.get_all()}")
25+
print(f"Span context baggage: {baggage.get_all(context=ctx)}")

docs/examples/datadog_exporter/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def server_request():
5656
with tracer.start_as_current_span("server-inner"):
5757
if param == "error":
5858
raise ValueError("forced server error")
59-
return "served: {}".format(param)
59+
return f"served: {param}"
6060

6161

6262
if __name__ == "__main__":

docs/examples/fork-process-model/flask-gunicorn/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def fibonacci():
5252
fast_span.set_attribute("n", n)
5353
fast_span.set_attribute("nth_fibonacci", ans)
5454

55-
return "F({}) is: ({})".format(n, ans)
55+
return f"F({n}) is: ({ans})"
5656

5757

5858
if __name__ == "__main__":

docs/examples/fork-process-model/flask-uwsgi/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def fibonacci():
7272
fast_span.set_attribute("n", n)
7373
fast_span.set_attribute("nth_fibonacci", ans)
7474

75-
return "F({}) is: ({})".format(n, ans)
75+
return f"F({n}) is: ({ans})"
7676

7777

7878
if __name__ == "__main__":

docs/examples/opentracing/rediscache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def inner(*args, **kwargs):
4545

4646
scope1.span.log_kv({"msg": "Cache miss, calling function"})
4747
with self.tracer.start_active_span(
48-
'Call "{}"'.format(func.__name__)
48+
f'Call "{func.__name__}"'
4949
) as scope2:
5050
scope2.span.set_tag("func", func.__name__)
5151
scope2.span.set_tag("args", str(args))

docs/getting_started/tests/test_flask.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
class TestFlask(unittest.TestCase):
2626
def test_flask(self):
2727
dirpath = os.path.dirname(os.path.realpath(__file__))
28-
server_script = "{}/../flask_example.py".format(dirpath)
28+
server_script = f"{dirpath}/../flask_example.py"
2929
server = subprocess.Popen(
3030
[sys.executable, server_script],
3131
stdout=subprocess.PIPE,

docs/getting_started/tests/test_tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class TestBasicTracerExample(unittest.TestCase):
2121
def test_basic_tracer(self):
2222
dirpath = os.path.dirname(os.path.realpath(__file__))
23-
test_script = "{}/../tracing_example.py".format(dirpath)
23+
test_script = f"{dirpath}/../tracing_example.py"
2424
output = subprocess.check_output(
2525
(sys.executable, test_script)
2626
).decode()

exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from time import sleep
2222
from typing import Any, Callable, Dict, Generic, List, Optional
2323
from typing import Sequence as TypingSequence
24-
from typing import Text, TypeVar
24+
from typing import TypeVar
2525
from urllib.parse import urlparse
2626

2727
from backoff import expo
@@ -115,14 +115,12 @@ def _translate_value(value: Any) -> KeyValue:
115115
# )
116116

117117
else:
118-
raise Exception(
119-
"Invalid type {} of value {}".format(type(value), value)
120-
)
118+
raise Exception(f"Invalid type {type(value)} of value {value}")
121119

122120
return any_value
123121

124122

125-
def _translate_key_values(key: Text, value: Any) -> KeyValue:
123+
def _translate_key_values(key: str, value: Any) -> KeyValue:
126124
return KeyValue(key=key, value=_translate_value(value))
127125

128126

exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def _translate_context_trace_state(self, sdk_span: ReadableSpan) -> None:
147147
if sdk_span.context.trace_state is not None:
148148
self._collector_span_kwargs["trace_state"] = ",".join(
149149
[
150-
"{}={}".format(key, value)
150+
f"{key}={value}"
151151
for key, value in (sdk_span.context.trace_state.items())
152152
]
153153
)
@@ -302,7 +302,7 @@ def _translate_data(
302302

303303
self._collector_span_kwargs["kind"] = getattr(
304304
CollectorSpan.SpanKind,
305-
"SPAN_KIND_{}".format(sdk_span.kind.name),
305+
f"SPAN_KIND_{sdk_span.kind.name}",
306306
)
307307

308308
instrumentation_library_spans.spans.append(

exporter/opentelemetry-exporter-otlp-proto-grpc/tests/performance/benchmarks/test_benchmark_trace_exporter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def get_tracer_with_processor(span_processor_class):
3333
return tracer
3434

3535

36-
class MockTraceServiceStub(object):
36+
class MockTraceServiceStub:
3737
def __init__(self, channel):
3838
self.Export = lambda *args, **kwargs: None
3939

@@ -51,8 +51,8 @@ def create_spans_to_be_exported():
5151
)
5252
for i in range(10):
5353
span.set_attribute(
54-
"benchmarkAttribute_{}".format(i),
55-
"benchmarkAttrValue_{}".format(i),
54+
f"benchmarkAttribute_{i}",
55+
f"benchmarkAttrValue_{i}",
5656
)
5757
span.end()
5858

@@ -79,8 +79,8 @@ def create_spans_to_be_exported():
7979
)
8080
for i in range(10):
8181
span.set_attribute(
82-
"benchmarkAttribute_{}".format(i),
83-
"benchmarkAttrValue_{}".format(i),
82+
f"benchmarkAttribute_{i}",
83+
f"benchmarkAttrValue_{i}",
8484
)
8585
span.end()
8686

0 commit comments

Comments
 (0)