comparison mercurial/vfs.py @ 43482:fc19f8ab8199

vfs: suppress some pytype errors around us using a private attribute Looking at threading._MainThread seems like we're probably a little unsupported, but since this code appears to work on both Python 2 and 3 I'm not going to sweat this for now. Differential Revision: https://phab.mercurial-scm.org/D7282
author Augie Fackler <augie@google.com>
date Wed, 06 Nov 2019 15:29:08 -0500
parents 8b0fa4de0064
children da9ecbb10368
comparison
equal deleted inserted replaced
43481:f5fcf7123a92 43482:fc19f8ab8199
305 asynchronously, on a background thread. 305 asynchronously, on a background thread.
306 """ 306 """
307 # Sharing backgroundfilecloser between threads is complex and using 307 # Sharing backgroundfilecloser between threads is complex and using
308 # multiple instances puts us at risk of running out of file descriptors 308 # multiple instances puts us at risk of running out of file descriptors
309 # only allow to use backgroundfilecloser when in main thread. 309 # only allow to use backgroundfilecloser when in main thread.
310 if not isinstance(threading.currentThread(), threading._MainThread): 310 if not isinstance(
311 threading.currentThread(),
312 threading._MainThread, # pytype: disable=module-attr
313 ):
311 yield 314 yield
312 return 315 return
313 vfs = getattr(self, 'vfs', self) 316 vfs = getattr(self, 'vfs', self)
314 if getattr(vfs, '_backgroundfilecloser', None): 317 if getattr(vfs, '_backgroundfilecloser', None):
315 raise error.Abort( 318 raise error.Abort(
316 _(b'can only have 1 active background file closer') 319 _(b'can only have 1 active background file closer')
317 ) 320 )
318 321
319 with backgroundfilecloser(ui, expectedcount=expectedcount) as bfc: 322 with backgroundfilecloser(ui, expectedcount=expectedcount) as bfc:
320 try: 323 try:
321 vfs._backgroundfilecloser = bfc 324 vfs._backgroundfilecloser = (
325 bfc # pytype: disable=attribute-error
326 )
322 yield bfc 327 yield bfc
323 finally: 328 finally:
324 vfs._backgroundfilecloser = None 329 vfs._backgroundfilecloser = (
330 None # pytype: disable=attribute-error
331 )
325 332
326 333
327 class vfs(abstractvfs): 334 class vfs(abstractvfs):
328 '''Operate files relative to a base directory 335 '''Operate files relative to a base directory
329 336
475 % mode 482 % mode
476 ) 483 )
477 fp = checkambigatclosing(fp) 484 fp = checkambigatclosing(fp)
478 485
479 if backgroundclose and isinstance( 486 if backgroundclose and isinstance(
480 threading.currentThread(), threading._MainThread 487 threading.currentThread(),
488 threading._MainThread, # pytype: disable=module-attr
481 ): 489 ):
482 if not self._backgroundfilecloser: 490 if not self._backgroundfilecloser:
483 raise error.Abort( 491 raise error.Abort(
484 _( 492 _(
485 b'backgroundclose can only be used when a ' 493 b'backgroundclose can only be used when a '