comparison mercurial/vfs.py @ 51881:adbb183c2f27

vfs: simplify the `abstractvfs.rename()` implementation PyCharm was yapping about `util.rename()` not returning anything, because it is typed to return `None`, but the value was captured and returned after calling `_avoidambig()`. Instead, drop all of that, unconditionally rename, and then call `_avoidambig()` if appropriate. While we're here, convert the ersatz ternary operator into a modern one to help pytype. When a variable is initialized the old way, pytype tends to assign the type of the LHS of the `and`. In this case, that's a bool, and it will get confused that bool doesn't have a `stat` attribute once this method gets more type annotations. (Currently it thinks the `checkambig` arg is `Any`, so it doesn't care.)
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 20 Sep 2024 01:16:16 -0400
parents f79f98733a5b
children e59e1d8d29d2
comparison
equal deleted inserted replaced
51880:f79f98733a5b 51881:adbb183c2f27
271 issue5584 for detail). 271 issue5584 for detail).
272 """ 272 """
273 self._auditpath(dst, b'w') 273 self._auditpath(dst, b'w')
274 srcpath = self.join(src) 274 srcpath = self.join(src)
275 dstpath = self.join(dst) 275 dstpath = self.join(dst)
276 oldstat = checkambig and util.filestat.frompath(dstpath) 276 oldstat = util.filestat.frompath(dstpath) if checkambig else None
277
278 util.rename(srcpath, dstpath)
279
277 if oldstat and oldstat.stat: 280 if oldstat and oldstat.stat:
278 ret = util.rename(srcpath, dstpath)
279 _avoidambig(dstpath, oldstat) 281 _avoidambig(dstpath, oldstat)
280 return ret
281 return util.rename(srcpath, dstpath)
282 282
283 def readlink(self, path: bytes) -> bytes: 283 def readlink(self, path: bytes) -> bytes:
284 return util.readlink(self.join(path)) 284 return util.readlink(self.join(path))
285 285
286 def removedirs(self, path: Optional[bytes] = None): 286 def removedirs(self, path: Optional[bytes] = None):