Patchwork D11470: util: avoid a name-error warning in the `mmapread` exception handler

login
register
mail settings
Submitter phabricator
Date Sept. 21, 2021, 3:39 p.m.
Message ID <differential-rev-PHID-DREV-vwutfyh2tn6xgf2pkbm7-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49788/
State Superseded
Headers show

Comments

phabricator - Sept. 21, 2021, 3:39 p.m.
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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]

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11470

AFFECTED FILES
  mercurial/util.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -449,8 +449,8 @@ 
         return b''
     elif size is None:
         size = 0
+    fd = getattr(fp, 'fileno', lambda: fp)()
     try:
-        fd = getattr(fp, 'fileno', lambda: fp)()
         return mmap.mmap(fd, size, access=mmap.ACCESS_READ)
     except ValueError:
         # Empty files cannot be mmapped, but mmapread should still work.  Check