Skip to content

Commit 8e4d93f

Browse files
committed
Fix mypy issues.
1 parent 55a0fda commit 8e4d93f

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

opentelemetry-api/src/opentelemetry/distributedcontext/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,26 @@ def __init__(
7474
self.value = value
7575

7676

77-
class DistributedContext(dict):
77+
class DistributedContext:
7878
"""A container for distributed context entries"""
7979

80+
def __init__(self, entries: typing.Iterable[Entry]) -> None:
81+
self._container = {entry.key: entry for entry in entries}
82+
8083
def get_entries(self) -> typing.Iterable[Entry]:
8184
"""Returns an immutable iterator to entries."""
82-
return self.values()
85+
return self._container.values()
8386

8487
def get_entry_value(
8588
self,
8689
key: EntryKey
87-
) -> typing.Optional[EntryValue]:
90+
) -> typing.Optional[Entry]:
8891
"""Returns the entry associated with a key or None
8992
9093
Args:
9194
key: the key with which to perform a lookup
9295
"""
93-
return self.get(key)
96+
return self._container.get(key)
9497

9598

9699
class DistributedContextManager:

opentelemetry-api/tests/distributedcontext/test_distributed_context.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ def setUp(self):
7272
distributedcontext.EntryKey("key"),
7373
distributedcontext.EntryValue("value"),
7474
)
75-
context = self.context = distributedcontext.DistributedContext()
76-
context[entry.key] = entry
75+
context = self.context = distributedcontext.DistributedContext((
76+
entry,
77+
))
7778

7879
def test_get_entries(self):
7980
self.assertIn(self.entry, self.context.get_entries())

opentelemetry-sdk/tests/distributedcontext/test_distributed_context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_use_context(self):
2727
self.assertIsNone(self.manager.get_current_context())
2828

2929
# Start initial context
30-
dctx = dctx_api.DistributedContext()
30+
dctx = dctx_api.DistributedContext(())
3131
with self.manager.use_context(dctx) as current:
3232
self.assertIs(current, dctx)
3333
self.assertIs(
@@ -36,7 +36,7 @@ def test_use_context(self):
3636
)
3737

3838
# Context is overridden
39-
nested_dctx = dctx_api.DistributedContext()
39+
nested_dctx = dctx_api.DistributedContext(())
4040
with self.manager.use_context(nested_dctx) as current:
4141
self.assertIs(current, nested_dctx)
4242
self.assertIs(

0 commit comments

Comments
 (0)