Skip to content

Commit a7bb5f5

Browse files
committed
Address additional ruff checks that could not be automatically fixed.
1 parent c25a6b8 commit a7bb5f5

File tree

8 files changed

+55
-55
lines changed

8 files changed

+55
-55
lines changed

opentelemetry-instrumentation/src/opentelemetry/instrumentation/_blobupload/api/__init__.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
)
3737

3838
__all__ = [
39-
Blob,
40-
BlobUploader,
41-
NOT_UPLOADED,
42-
detect_content_type,
43-
generate_labels_for_event,
44-
generate_labels_for_span,
45-
generate_labels_for_span_event,
46-
BlobUploaderProvider,
47-
get_blob_uploader,
48-
set_blob_uploader_provider,
39+
"Blob",
40+
"BlobUploader",
41+
"NOT_UPLOADED",
42+
"detect_content_type",
43+
"generate_labels_for_event",
44+
"generate_labels_for_span",
45+
"generate_labels_for_span_event",
46+
"BlobUploaderProvider",
47+
"get_blob_uploader",
48+
"set_blob_uploader_provider",
4949
]

opentelemetry-instrumentation/src/opentelemetry/instrumentation/_blobupload/backend/google/gcs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
)
1818

1919
__all__ = [
20-
GcsBlobUploader
20+
"GcsBlobUploader"
2121
]

opentelemetry-instrumentation/src/opentelemetry/instrumentation/_blobupload/backend/google/gcs/_gcs_impl.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def _path_for_span_event(trace_id, span_id, event_index):
5959

6060
def _path_segment_from_labels(labels):
6161
"""Returns a path segment based on blob label metadata.
62-
62+
6363
This aims to return paths like:
6464
6565
'traces/12345/spans/56789'
@@ -120,7 +120,7 @@ class GcsBlobUploader(BlobUploader):
120120

121121
def __init__(self, prefix: str, client:Optional[GcsClient]=None):
122122
"""Intialize the GcsBlobUploader class.
123-
123+
124124
Args:
125125
- prefix: a string beginning with "gs://" that includes
126126
the Google Cloud Storage bucket to which to write as
@@ -132,7 +132,7 @@ def __init__(self, prefix: str, client:Optional[GcsClient]=None):
132132
Credentials). Supply your own instance if you'd like to
133133
use non-default configuration (e.g. to use an explicit
134134
credential other than the one in the environment).
135-
135+
136136
Known Failure Modes:
137137
- Missing 'google-cloud-storage' library dependency.
138138
- Failure to construct the client (e.g. absence of a valid
@@ -145,7 +145,7 @@ def __init__(self, prefix: str, client:Optional[GcsClient]=None):
145145

146146
def upload_async(self, blob: Blob) -> str:
147147
"""Upload the specified blob in the background.
148-
148+
149149
Generates a URI from the blob, based on the prefix supplied
150150
to the constructor as well as the labels of the Blob (may
151151
also include entropy or other random components). Immediately

opentelemetry-instrumentation/src/opentelemetry/instrumentation/_blobupload/utils/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
)
2323

2424
__all__ = [
25-
blob_uploader_from_simple_blob_uploader,
26-
SimpleBlobUploader,
25+
"blob_uploader_from_simple_blob_uploader",
26+
"SimpleBlobUploader",
2727
]

opentelemetry-instrumentation/src/opentelemetry/instrumentation/_blobupload/utils/simple_blob_uploader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class SimpleBlobUploader(abc.ABC):
2525
@abc.abstractmethod
2626
def generate_destination_uri(self, blob: Blob) -> str:
2727
"""Generates a URI of where the blob will get written.
28-
28+
2929
Args:
3030
blob: the blob which will be uploaded.
3131

opentelemetry-instrumentation/src/opentelemetry/instrumentation/_blobupload/utils/simple_blob_uploader_adaptor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __call__(self):
6060
_logger.debug('Uploading blob to "{}".'.format(self._uri))
6161
try:
6262
self._simple_uploader.upload_sync(self._uri, self._blob)
63-
except:
63+
except Exception:
6464
_logger.exception('Failed to upload blob to "{}".'.format(self._uri))
6565

6666

@@ -105,7 +105,7 @@ def _get_or_create_default_executor():
105105

106106
class _SimpleBlobUploaderAdaptor(BlobUploader):
107107
"""Implementation of 'BlobUploader' wrapping a 'SimpleBlobUploader'.
108-
108+
109109
This implements the core of the function 'blob_uploader_from_simple_blob_uploader'.
110110
"""
111111

@@ -127,7 +127,7 @@ def _do_in_background(self, action):
127127

128128
def blob_uploader_from_simple_blob_uploader(simple_uploader: SimpleBlobUploader) -> BlobUploader:
129129
"""Implements a 'BlobUploader' using the supplied 'SimpleBlobUploader'.
130-
130+
131131
The purpose of this function is to allow backend implementations/vendors to be able to
132132
implement their logic much more simply, using synchronous uploading interfaces.
133133

opentelemetry-instrumentation/tests/_blobupload/api/test_content_type.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
from opentelemetry.instrumentation._blobupload.api import detect_content_type
1414

1515

16-
def create_test_image(format):
16+
def create_test_image(image_format):
1717
"""Helper for creating a PIL Image for verifying image format support."""
1818
test_img = Image.new("RGB", (2, 2))
1919
output_buffer = io.BytesIO()
20-
test_img.save(output_buffer, format)
20+
test_img.save(output_buffer, image_format)
2121
result = output_buffer.getvalue()
2222
output_buffer.close()
2323
test_img.close()
@@ -27,33 +27,33 @@ def create_test_image(format):
2727
class TestContentType(unittest.TestCase):
2828

2929
def test_handles_empty_correctly(self):
30-
input = bytes()
31-
output = detect_content_type(input)
32-
self.assertEqual(output, "application/octet-stream")
30+
data = bytes()
31+
content_type = detect_content_type(data)
32+
self.assertEqual(content_type, "application/octet-stream")
3333

3434
def test_detects_plaintext(self):
35-
input = "this is just regular text"
36-
output = detect_content_type(input.encode())
37-
self.assertEqual(output, "text/plain")
35+
data = "this is just regular text"
36+
content_type = detect_content_type(data.encode())
37+
self.assertEqual(content_type, "text/plain")
3838

3939
def test_detects_json(self):
40-
input = """{
40+
data = """{
4141
"this": {
4242
"contains": "json"
4343
}
4444
}"""
45-
output = detect_content_type(input.encode())
46-
self.assertEqual(output, "application/json")
45+
content_type = detect_content_type(data.encode())
46+
self.assertEqual(content_type, "application/json")
4747

4848
def test_detects_jpeg(self):
49-
input = create_test_image("jpeg")
50-
output = detect_content_type(input)
51-
self.assertEqual(output, "image/jpeg")
49+
data = create_test_image("jpeg")
50+
content_type = detect_content_type(data)
51+
self.assertEqual(content_type, "image/jpeg")
5252

5353
def test_detects_png(self):
54-
input = create_test_image("png")
55-
output = detect_content_type(input)
56-
self.assertEqual(output, "image/png")
54+
data = create_test_image("png")
55+
content_type = detect_content_type(data)
56+
self.assertEqual(content_type, "image/png")
5757

5858

5959
if __name__ == "__main__":

opentelemetry-instrumentation/tests/_blobupload/backend/google/gcs/test_gcs_blob_uploader.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,32 @@ def __init__(self):
3333
def reset(self):
3434
self._storage = {}
3535

36-
def get(self, id):
37-
while id not in self._done:
36+
def get(self, gcs_blob_id):
37+
while gcs_blob_id not in self._done:
3838
self._queue.get()
39-
return self._storage.get(id)
39+
return self._storage.get(gcs_blob_id)
4040

41-
def upload_from_file(self, id, data, content_type):
41+
def upload_from_file(self, gcs_blob_id, data, content_type):
4242
b = Blob(data.read(), content_type=content_type)
43-
self._storage[id] = b
43+
self._storage[gcs_blob_id] = b
4444

45-
def update_metadata(self, id, new_metadata):
46-
old = self._storage[id]
45+
def update_metadata(self, gcs_blob_id, new_metadata):
46+
old = self._storage[gcs_blob_id]
4747
b = Blob(old.raw_bytes, content_type=old.content_type, labels=new_metadata)
48-
self._storage[id] = b
49-
self._done.add(id)
50-
self._queue.put(id)
48+
self._storage[gcs_blob_id] = b
49+
self._done.add(gcs_blob_id)
50+
self._queue.put(gcs_blob_id)
5151

5252

5353
class FakeGcsBlob(object):
5454

55-
def __init__(self, id, fake_gcs):
56-
self._id = id
55+
def __init__(self, gcs_blob_id, fake_gcs):
56+
self._gcs_blob_id = gcs_blob_id
5757
self._fake_gcs = fake_gcs
5858
self._metadata = {}
5959

6060
def upload_from_file(self, iodata, content_type):
61-
self._fake_gcs.upload_from_file(self._id, iodata, content_type)
61+
self._fake_gcs.upload_from_file(self._gcs_blob_id, iodata, content_type)
6262

6363
@property
6464
def metadata(self):
@@ -67,7 +67,7 @@ def metadata(self):
6767
@metadata.setter
6868
def metadata(self, m):
6969
self._metadata = m
70-
self._fake_gcs.update_metadata(self._id, self._metadata)
70+
self._fake_gcs.update_metadata(self._gcs_blob_id, self._metadata)
7171

7272

7373
def mocked_blob_from_uri(fake_gcs):
@@ -81,8 +81,8 @@ def gcs_blob_from_uri(uri, client):
8181
_gcs_client_wrapper.set_gcs_blob_from_uri(mocked_blob_from_uri(_gcs_mock))
8282

8383

84-
def get_from_fake_gcs(id):
85-
return _gcs_mock.get(id)
84+
def get_from_fake_gcs(gcs_blob_id):
85+
return _gcs_mock.get(gcs_blob_id)
8686

8787

8888
class GcsBlobUploaderTestCase(unittest.TestCase):
@@ -92,7 +92,7 @@ def setUp(self):
9292

9393
def test_constructor_throws_if_prefix_not_uri(self):
9494
with self.assertRaises(ValueError):
95-
GcsBlobUploader("not a valid URI")
95+
GcsBlobUploader("not a valgcs_blob_id URI")
9696

9797
def test_constructor_throws_if_prefix_not_gs_protocol(self):
9898
with self.assertRaises(ValueError):

0 commit comments

Comments
 (0)