44class 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
12- self .sec = int (sec )
13- self .nsec = int (nsec )
12+ self .sec : int = int (sec )
13+ self .nsec : int = 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):
4545class 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