| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 39d2360 commit bbeb7c3
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,30 +4,30 @@ | |||
| 4 | 4 | class Timestamp: | |
| 5 | 5 | """A nanosecond-resolution timestamp.""" | |
| 6 | 6 | ||
| 7 | - def __init__(self, sec, nsec): | ||
| 7 | + def __init__(self, sec: Union[int, float], nsec: Union[int, float]) -> None: | ||
| 8 | 8 | if nsec < 0 or nsec >= 1e9: | |
| 9 | 9 | raise ValueError(f"Invalid value for nanoseconds in Timestamp: {nsec}") | |
| 10 | 10 | if sec < 0: | |
| 11 | 11 | nsec = -nsec | |
| 12 | - self.sec = int(sec) | ||
| 13 | - self.nsec = int(nsec) | ||
| 12 | + self.sec: int = int(sec) | ||
| 13 | + self.nsec: int = int(nsec) | ||
| 14 | 14 | ||
| 15 | - def __str__(self): | ||
| 15 | + def __str__(self) -> str: | ||
| 16 | 16 | return f"{self.sec}.{self.nsec:09d}" | |
| 17 | 17 | ||
| 18 | - def __repr__(self): | ||
| 18 | + def __repr__(self) -> str: | ||
| 19 | 19 | return f"Timestamp({self.sec}, {self.nsec})" | |
| 20 | 20 | ||
| 21 | - def __float__(self): | ||
| 21 | + def __float__(self) -> float: | ||
| 22 | 22 | return float(self.sec) + float(self.nsec) / 1e9 | |
| 23 | 23 | ||
| 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 | ||
| 26 | 26 | ||
| 27 | - def __ne__(self, other): | ||
| 27 | + def __ne__(self, other: object) -> bool: | ||
| 28 | 28 | return not self == other | |
| 29 | 29 | ||
| 30 | - def __gt__(self, other): | ||
| 30 | + def __gt__(self, other: "Timestamp") -> bool: | ||
| 31 | 31 | return self.sec > other.sec or self.nsec > other.nsec | |
| 32 | 32 | ||
| 33 | 33 | ||
@@ -45,6 +45,6 @@ class Exemplar(NamedTuple): | |||
| 45 | 45 | class Sample(NamedTuple): | |
| 46 | 46 | name: str | |
| 47 | 47 | labels: Dict[str, str] | |
| 48 | - value: float | ||
| 48 | + value: Union[int, float] | ||
| 49 | 49 | timestamp: Optional[Union[float, Timestamp]] = None | |
| 50 | 50 | exemplar: Optional[Exemplar] = None | |
| Back | FazBrowse Home | New Git URL |
0 commit comments