Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7688332

Browse files
authored
boundlist typing wip (open-telemetry#1385)
1 parent 3d48ecd commit 7688332

File tree

5 files changed

+91
-12
lines changed

5 files changed

+91
-12
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ __pycache__
2424
venv*/
2525
.venv*/
2626
opentelemetry-python-contrib/
27+
# in case of symlink
28+
opentelemetry-python-contrib
2729

2830
# Installer logs
2931
pip-log.txt

opentelemetry-api/src/opentelemetry/util/types.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,28 @@
1313
# limitations under the License.
1414

1515

16-
from typing import Callable, Mapping, Optional, Sequence, Union
16+
from typing import Callable, Mapping, Optional, Sequence, Tuple, Union
1717

1818
AttributeValue = Union[
1919
str,
2020
bool,
2121
int,
2222
float,
23-
Sequence[Union[None, str]],
24-
Sequence[Union[None, bool]],
25-
Sequence[Union[None, int]],
26-
Sequence[Union[None, float]],
23+
Sequence[Optional[str]],
24+
Sequence[Optional[bool]],
25+
Sequence[Optional[int]],
26+
Sequence[Optional[float]],
27+
]
28+
AttributeValueAsKey = Union[
29+
str,
30+
bool,
31+
int,
32+
float,
33+
Tuple[Optional[str], ...],
34+
Tuple[Optional[bool], ...],
35+
Tuple[Optional[int], ...],
36+
Tuple[Optional[float], ...],
2737
]
2838
Attributes = Optional[Mapping[str, AttributeValue]]
39+
AttributesAsKey = Tuple[Tuple[str, AttributeValueAsKey], ...]
2940
AttributesFormatter = Callable[[], Attributes]

opentelemetry-sdk/src/opentelemetry/sdk/util/__init__.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,11 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
1415
import datetime
1516
import threading
1617
from collections import OrderedDict, deque
17-
18-
try:
19-
# pylint: disable=ungrouped-imports
20-
from collections.abc import MutableMapping, Sequence
21-
except ImportError:
22-
# pylint: disable=no-name-in-module,ungrouped-imports
23-
from collections import MutableMapping, Sequence
18+
from collections.abc import MutableMapping, Sequence
2419

2520

2621
def ns_to_iso_str(nanoseconds):
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from typing import (
16+
Iterable,
17+
Iterator,
18+
Mapping,
19+
MutableMapping,
20+
Sequence,
21+
TypeVar,
22+
overload,
23+
)
24+
25+
from opentelemetry.util.types import AttributesAsKey, AttributeValue
26+
27+
_T = TypeVar("_T")
28+
_KT = TypeVar("_KT")
29+
_VT = TypeVar("_VT")
30+
31+
def ns_to_iso_str(nanoseconds: int) -> str: ...
32+
def get_dict_as_key(
33+
labels: Mapping[str, AttributeValue]
34+
) -> AttributesAsKey: ...
35+
36+
class BoundedList(Sequence[_T]):
37+
"""An append only list with a fixed max size.
38+
39+
Calls to `append` and `extend` will drop the oldest elements if there is
40+
not enough room.
41+
"""
42+
43+
def __init__(self, maxlen: int): ...
44+
def insert(self, index: int, value: _T) -> None: ...
45+
@overload
46+
def __getitem__(self, i: int) -> _T: ...
47+
@overload
48+
def __getitem__(self, s: slice) -> Sequence[_T]: ...
49+
def __len__(self) -> int: ...
50+
def append(self, item: _T): ...
51+
def extend(self, seq: Sequence[_T]): ...
52+
@classmethod
53+
def from_seq(cls, maxlen: int, seq: Iterable[_T]) -> BoundedList[_T]: ...
54+
55+
class BoundedDict(MutableMapping[_KT, _VT]):
56+
"""An ordered dict with a fixed max capacity.
57+
58+
Oldest elements are dropped when the dict is full and a new element is
59+
added.
60+
"""
61+
62+
def __init__(self, maxlen: int): ...
63+
def __getitem__(self, k: _KT) -> _VT: ...
64+
def __setitem__(self, k: _KT, v: _VT) -> None: ...
65+
def __delitem__(self, v: _KT) -> None: ...
66+
def __iter__(self) -> Iterator[_KT]: ...
67+
def __len__(self) -> int: ...
68+
@classmethod
69+
def from_map(
70+
cls, maxlen: int, mapping: Mapping[_KT, _VT]
71+
) -> BoundedDict[_KT, _VT]: ...

opentelemetry-sdk/src/opentelemetry/sdk/util/py.typed

Whitespace-only changes.

0 commit comments

Comments
 (0)