comparison mercurial/util.py @ 48010:ae79611e3115

util: avoid a name-error warning in the `mmapread` exception handler Newly caught by pytype 2021-09-09. File "/mnt/c/Users/Matt/hg/mercurial/util.py", line 458, in mmapread: Name 'fd' is not defined [name-error] Differential Revision: https://phab.mercurial-scm.org/D11470
author Matt Harbison <matt_harbison@yahoo.com>
date Mon, 20 Sep 2021 10:46:35 -0400
parents bb917eea1605
children 376d08ae904f
comparison
equal deleted inserted replaced
48009:94d4a3f78e99 48010:ae79611e3115
447 # size of 0 to mmap.mmap() means "all data" 447 # size of 0 to mmap.mmap() means "all data"
448 # rather than "zero bytes", so special case that. 448 # rather than "zero bytes", so special case that.
449 return b'' 449 return b''
450 elif size is None: 450 elif size is None:
451 size = 0 451 size = 0
452 fd = getattr(fp, 'fileno', lambda: fp)()
452 try: 453 try:
453 fd = getattr(fp, 'fileno', lambda: fp)()
454 return mmap.mmap(fd, size, access=mmap.ACCESS_READ) 454 return mmap.mmap(fd, size, access=mmap.ACCESS_READ)
455 except ValueError: 455 except ValueError:
456 # Empty files cannot be mmapped, but mmapread should still work. Check 456 # Empty files cannot be mmapped, but mmapread should still work. Check
457 # if the file is empty, and if so, return an empty buffer. 457 # if the file is empty, and if so, return an empty buffer.
458 if os.fstat(fd).st_size == 0: 458 if os.fstat(fd).st_size == 0: