8000 Add type annotations to samples.py · prometheus/client_python@17ceb2c · GitHub
[go: up one dir, main page]

Skip to content

Commit 17ceb2c

Browse files
committed
Add type annotations to samples.py
Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
1 parent 56b514e commit 17ceb2c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

prometheus_client/samples.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@
44
class Timestamp:
55
"""A nanosecond-resolution timestamp."""
66

7-
def __init__(self, sec, nsec):
7+
def __init__(self, sec: Union[int, float], nsec: Union[int, float]) -> None:
88
if nsec < 0 or nsec >= 1e9:
99
raise ValueError(f"Invalid value for nanoseconds in Timestamp: {nsec}")
1010
if sec < 0:
1111
nsec = -nsec
1212
self.sec = int(sec)
1313
self.nsec = int(nsec)
1414

15-
def __str__(self):
15+
def __str__(self) -> str:
1616
return f"{self.sec}.{self.nsec:09d}"
1717

18-
def __repr__(self):
18+
def __repr__(self) -> str:
1919
return f"Timestamp({self.sec}, {self.nsec})"
2020

21-
def __float__(self):
21+
def __float__(self) -> float:
2222
return float(self.sec) + float(self.nsec) / 1e9
2323

24-
def __eq__(self, other):
25-
return type(self) == type(other) and self.sec == other.sec and self.nsec == other.nsec
24+
def __eq__(self, other: object) -> bool:
25+
return isinstance(other, Timestamp) and self.sec == other.sec and self.nsec == other.nsec
2626

27-
def __ne__(self, other):
27+
def __ne__(self, other: object) -> bool:
2828
return not self == other
2929

30-
def __gt__(self, other):
30+
def __gt__(self, other: "Timestamp") -> bool:
3131
return self.sec > other.sec or self.nsec > other.nsec
3232

3333

@@ -45,6 +45,6 @@ class Exemplar(NamedTuple):
4545
class Sample(NamedTuple):
4646
name: str
4747
labels: Dict[str, str]
48-
value: float
48+
value: Union[int, float]
4949
timestamp: Optional[Union[float, Timestamp]] = None
5050
exemplar: Optional[Exemplar] = None

0 commit comments

Comments
 (0)
0