Skip to content

Commit 5902b35

Browse files
committed
Reformat with ruff.
1 parent 0e441b2 commit 5902b35

File tree

4 files changed

+48
-27
lines changed

4 files changed

+48
-27
lines changed

instrumentation-genai/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/allowlist_util.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import re
1615
import os
17-
from typing import Callable, Iterable, Optional, Set, Union
16+
import re
17+
from typing import Iterable, Optional, Set
1818

1919
ALLOWED = True
2020
DENIED = False
@@ -31,9 +31,8 @@ def _parse_env_list(s: str) -> Set[str]:
3131

3232

3333
class _CompoundMatcher:
34-
3534
def __init__(self, entries: Set[str]):
36-
self._match_all = '*' in entries
35+
self._match_all = "*" in entries
3736
self._entries = entries
3837
self._regex_matcher = None
3938
regex_entries = []
@@ -48,10 +47,10 @@ def __init__(self, entries: Set[str]):
4847
entry = entry.replace("*", ".*")
4948
regex_entries.append(f"({entry})")
5049
if regex_entries:
51-
joined_regex = '|'.join(regex_entries)
50+
joined_regex = "|".join(regex_entries)
5251
regex_str = f"^({joined_regex})$"
5352
self._regex_matcher = re.compile(regex_str)
54-
53+
5554
@property
5655
def match_all(self):
5756
return self._match_all
@@ -61,7 +60,9 @@ def matches(self, x):
6160
return True
6261
if x in self._entries:
6362
return True
64-
if (self._regex_matcher is not None) and (self._regex_matcher.fullmatch(x)):
63+
if (self._regex_matcher is not None) and (
64+
self._regex_matcher.fullmatch(x)
65+
):
6566
return True
6667
return False
6768

@@ -74,7 +75,9 @@ def __init__(
7475
):
7576
self._includes = _CompoundMatcher(set(includes or []))
7677
self._excludes = _CompoundMatcher(set(excludes or []))
77-
assert ((not self._includes.match_all) or (not self._excludes.match_all)), "Can't have '*' in both includes and excludes."
78+
assert (not self._includes.match_all) or (
79+
not self._excludes.match_all
80+
), "Can't have '*' in both includes and excludes."
7881

7982
def allowed(self, x: str):
8083
if self._excludes.match_all:

instrumentation-genai/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/dict_util.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import logging
1615
import json
17-
from typing import Any, Callable, Dict, Optional, Protocol, Sequence, Set, Tuple, Union
16+
import logging
17+
from typing import (
18+
Any,
19+
Dict,
20+
Optional,
21+
Protocol,
22+
Sequence,
23+
Set,
24+
Tuple,
25+
Union,
26+
)
1827

1928
Primitive = Union[bool, str, int, float]
2029
BoolList = list[bool]
@@ -27,15 +36,15 @@
2736

2837

2938
class FlattenFunc(Protocol):
30-
3139
def __call__(
3240
self,
3341
key: str,
3442
value: Any,
3543
exclude_keys: Set[str],
3644
rename_keys: Dict[str, str],
3745
flatten_functions: Dict[str, "FlattenFunc"],
38-
**kwargs: Any) -> Any:
46+
**kwargs: Any,
47+
) -> Any:
3948
return None
4049

4150

@@ -152,12 +161,18 @@ def _flatten_compound_value(
152161
flatten_functions=flatten_functions,
153162
)
154163
if _from_json:
155-
_logger.debug("Cannot flatten value with key %s; value: %s", key, value)
164+
_logger.debug(
165+
"Cannot flatten value with key %s; value: %s", key, value
166+
)
156167
return {}
157168
try:
158169
json_string = json.dumps(value)
159170
except TypeError:
160-
_logger.debug("Cannot flatten value with key %s; value: %s. Not JSON serializable.", key, value)
171+
_logger.debug(
172+
"Cannot flatten value with key %s; value: %s. Not JSON serializable.",
173+
key,
174+
value,
175+
)
161176
return {}
162177
json_value = json.loads(json_string)
163178
return _flatten_value(

instrumentation-genai/opentelemetry-instrumentation-google-genai/tests/utils/test_allowlist_util.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ def test_includes_and_excludes():
6767

6868

6969
def test_includes_and_excludes_with_wildcards():
70-
allow_list = AllowList(includes=["abc", "xyz", "xyz.*"], excludes=["xyz.foo", "xyz.foo.*"])
70+
allow_list = AllowList(
71+
includes=["abc", "xyz", "xyz.*"], excludes=["xyz.foo", "xyz.foo.*"]
72+
)
7173
assert allow_list.allowed("abc")
7274
assert allow_list.allowed("xyz")
7375
assert not allow_list.allowed("xyz.foo")

instrumentation-genai/opentelemetry-instrumentation-google-genai/tests/utils/test_dict_util.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
from pydantic import BaseModel
16+
1617
from opentelemetry.instrumentation.google_genai import dict_util
1718

1819

@@ -208,25 +209,25 @@ def test_flatten_with_mixed_structures():
208209

209210
def test_flatten_with_complex_object_not_json_serializable():
210211
result = dict_util.flatten_dict(
211-
{
212-
"cannot_serialize_directly": NotJsonSerializable(),
213-
}
214-
)
212+
{
213+
"cannot_serialize_directly": NotJsonSerializable(),
214+
}
215+
)
215216
assert result is not None
216217
assert isinstance(result, dict)
217218
assert len(result) == 0
218219

219220

220221
def test_flatten_good_with_non_serializable_complex_object():
221222
result = dict_util.flatten_dict(
222-
{
223-
"foo": {
224-
"bar": "blah",
225-
"baz": 5,
226-
},
227-
"cannot_serialize_directly": NotJsonSerializable(),
228-
}
229-
)
223+
{
224+
"foo": {
225+
"bar": "blah",
226+
"baz": 5,
227+
},
228+
"cannot_serialize_directly": NotJsonSerializable(),
229+
}
230+
)
230231
assert result == {
231232
"foo.bar": "blah",
232233
"foo.baz": 5,

0 commit comments

Comments
 (0)