|
40 | 40 | _EXPIRE_STALE_TIME_MS = 500
|
41 | 41 | _RECENT_TIME_MS = 250
|
42 | 42 |
|
| 43 | +_float = float |
| 44 | +_int = int |
43 | 45 |
|
44 | 46 | if TYPE_CHECKING:
|
45 | 47 | from ._protocol.incoming import DNSIncoming
|
@@ -172,32 +174,36 @@ def __eq__(self, other: Any) -> bool: # pylint: disable=no-self-use
|
172 | 174 | def suppressed_by(self, msg: 'DNSIncoming') -> bool:
|
173 | 175 | """Returns true if any answer in a message can suffice for the
|
174 | 176 | information held in this record."""
|
175 |
| - return any(self._suppressed_by_answer(record) for record in msg.answers) |
| 177 | + answers = msg.answers |
| 178 | + for record in answers: |
| 179 | + if self._suppressed_by_answer(record): |
| 180 | + return True |
| 181 | + return False |
176 | 182 |
|
177 |
| - def _suppressed_by_answer(self, other) -> bool: # type: ignore[no-untyped-def] |
| 183 | + def _suppressed_by_answer(self, other: 'DNSRecord') -> bool: |
178 | 184 | """Returns true if another record has same name, type and class,
|
179 | 185 | and if its TTL is at least half of this record's."""
|
180 | 186 | return self == other and other.ttl > (self.ttl / 2)
|
181 | 187 |
|
182 |
| - def get_expiration_time(self, percent: int) -> float: |
| 188 | + def get_expiration_time(self, percent: _int) -> float: |
183 | 189 | """Returns the time at which this record will have expired
|
184 | 190 | by a certain percentage."""
|
185 | 191 | return self.created + (percent * self.ttl * 10)
|
186 | 192 |
|
187 | 193 | # TODO: Switch to just int here
|
188 |
| - def get_remaining_ttl(self, now: float) -> Union[int, float]: |
| 194 | + def get_remaining_ttl(self, now: _float) -> Union[int, float]: |
189 | 195 | """Returns the remaining TTL in seconds."""
|
190 | 196 | return max(0, millis_to_seconds((self.created + (_EXPIRE_FULL_TIME_MS * self.ttl)) - now))
|
191 | 197 |
|
192 |
| - def is_expired(self, now: float) -> bool: |
| 198 | + def is_expired(self, now: _float) -> bool: |
193 | 199 | """Returns true if this record has expired."""
|
194 | 200 | return self.created + (_EXPIRE_FULL_TIME_MS * self.ttl) <= now
|
195 | 201 |
|
196 |
| - def is_stale(self, now: float) -> bool: |
| 202 | + def is_stale(self, now: _float) -> bool: |
197 | 203 | """Returns true if this record is at least half way expired."""
|
198 | 204 | return self.created + (_EXPIRE_STALE_TIME_MS * self.ttl) <= now
|
199 | 205 |
|
200 |
| - def is_recent(self, now: float) -> bool: |
| 206 | + def is_recent(self, now: _float) -> bool: |
201 | 207 | """Returns true if the record more than one quarter of its TTL remaining."""
|
202 | 208 | return self.created + (_RECENT_TIME_MS * self.ttl) > now
|
203 | 209 |
|
|
0 commit comments