Mercurial > hg-stable
comparison mercurial/lock.py @ 51303:81224afd938d
lock: properly convert error to bytes
Flagged by pytype when a later changeset is applied moving typing comment to annotation.
We fix this ahead of the annotation change to make sure pytype remains happy
after the change.
We have to do fairly crazy dance for pytype to be happy. This probably comes
from the fact IOError.filename probably claims to be `str` while it is actually
`bytes` if the filename raising that `IOError` is bytes.
At the same time, `IOError.strerror` is consistently `str` and should be passed
as `str` everywhere.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 20 Dec 2023 20:13:22 +0100 |
parents | 18c8c18993f0 |
children | 9da3fcc5f70f |
comparison
equal
deleted
inserted
replaced
51302:9d3721552b6c | 51303:81224afd938d |
---|---|
10 import errno | 10 import errno |
11 import os | 11 import os |
12 import signal | 12 import signal |
13 import socket | 13 import socket |
14 import time | 14 import time |
15 import typing | |
15 import warnings | 16 import warnings |
16 | 17 |
17 from .i18n import _ | 18 from .i18n import _ |
18 | 19 |
19 from . import ( | 20 from . import ( |
152 if delay == debugidx: | 153 if delay == debugidx: |
153 printwarning(ui.debug, inst.locker) | 154 printwarning(ui.debug, inst.locker) |
154 if delay == warningidx: | 155 if delay == warningidx: |
155 printwarning(ui.warn, inst.locker) | 156 printwarning(ui.warn, inst.locker) |
156 if timeout <= delay: | 157 if timeout <= delay: |
158 assert isinstance(inst.filename, bytes) | |
157 raise error.LockHeld( | 159 raise error.LockHeld( |
158 errno.ETIMEDOUT, inst.filename, l.desc, inst.locker | 160 errno.ETIMEDOUT, |
161 typing.cast(bytes, inst.filename), | |
162 l.desc, | |
163 inst.locker, | |
159 ) | 164 ) |
160 time.sleep(1) | 165 time.sleep(1) |
161 delay += 1 | 166 delay += 1 |
162 | 167 |
163 l.delay = delay | 168 l.delay = delay |
288 self.vfs.join(self.f), | 293 self.vfs.join(self.f), |
289 self.desc, | 294 self.desc, |
290 locker, | 295 locker, |
291 ) | 296 ) |
292 else: | 297 else: |
298 assert isinstance(why.filename, bytes) | |
299 assert isinstance(why.strerror, str) | |
293 raise error.LockUnavailable( | 300 raise error.LockUnavailable( |
294 why.errno, why.strerror, why.filename, self.desc | 301 why.errno, |
302 why.strerror, | |
303 typing.cast(bytes, why.filename), | |
304 self.desc, | |
295 ) | 305 ) |
296 | 306 |
297 if not self.held: | 307 if not self.held: |
298 # use empty locker to mean "busy for frequent lock/unlock | 308 # use empty locker to mean "busy for frequent lock/unlock |
299 # by many processes" | 309 # by many processes" |