comparison mercurial/manifest.py @ 52644:e627cc25b6f3

pyupgrade: rewrite `yield` statements in a loop to `yield from` This is the `legacy` fixer in `pyupgrade`, with the `yield` statement yielding loop commented back in. This seems to help pytype in some cases, and hurt it in others. But that can be manually fixed later. Note that it's possibly buggy in that it aggressively changed `import-checker.py` to `yield from 'fcntl', 'grp', 'pwd', 'select', 'termios': # Unix only`, which is invalid syntax. Possibly it needed help from the token fixer that I've disabled locally (because that wants to make a bunch of unrelated changes). Just change those few places to yield from a list, to avoid having to constantly revert that.
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 05 Jan 2025 22:26:16 -0500
parents 5cc8deb96b48
children 4cb75772818d
comparison
equal deleted inserted replaced
52643:5cc8deb96b48 52644:e627cc25b6f3
586 an entirely new manifest. 586 an entirely new manifest.
587 587
588 It also reports nonexistent files by marking them bad with match.bad(). 588 It also reports nonexistent files by marking them bad with match.bad().
589 """ 589 """
590 if match.always(): 590 if match.always():
591 for f in iter(self): 591 yield from iter(self)
592 yield f
593 return 592 return
594 593
595 fset = set(match.files()) 594 fset = set(match.files())
596 595
597 # avoid the entire walk if we're only looking for specific files 596 # avoid the entire walk if we're only looking for specific files
1004 itertools.chain(self._dirs.items(), self._files.items()) 1003 itertools.chain(self._dirs.items(), self._files.items())
1005 ): 1004 ):
1006 if p in self._files: 1005 if p in self._files:
1007 yield self._subpath(p), n, self._flags.get(p, b'') 1006 yield self._subpath(p), n, self._flags.get(p, b'')
1008 else: 1007 else:
1009 for x in n.iterentries(): 1008 yield from n.iterentries()
1010 yield x
1011 1009
1012 def items(self) -> Iterator[Tuple[bytes, Union[bytes, 'treemanifest']]]: 1010 def items(self) -> Iterator[Tuple[bytes, Union[bytes, 'treemanifest']]]:
1013 self._load() 1011 self._load()
1014 self._loadalllazy() 1012 self._loadalllazy()
1015 for p, n in sorted( 1013 for p, n in sorted(
1016 itertools.chain(self._dirs.items(), self._files.items()) 1014 itertools.chain(self._dirs.items(), self._files.items())
1017 ): 1015 ):
1018 if p in self._files: 1016 if p in self._files:
1019 yield self._subpath(p), n 1017 yield self._subpath(p), n
1020 else: 1018 else:
1021 for f, sn in n.items(): 1019 yield from n.items()
1022 yield f, sn
1023 1020
1024 iteritems = items 1021 iteritems = items
1025 1022
1026 def iterkeys(self) -> Iterator[bytes]: 1023 def iterkeys(self) -> Iterator[bytes]:
1027 self._load() 1024 self._load()
1028 self._loadalllazy() 1025 self._loadalllazy()
1029 for p in sorted(itertools.chain(self._dirs, self._files)): 1026 for p in sorted(itertools.chain(self._dirs, self._files)):
1030 if p in self._files: 1027 if p in self._files:
1031 yield self._subpath(p) 1028 yield self._subpath(p)
1032 else: 1029 else:
1033 for f in self._dirs[p]: 1030 yield from self._dirs[p]
1034 yield f
1035 1031
1036 def keys(self) -> List[bytes]: 1032 def keys(self) -> List[bytes]:
1037 return list(self.iterkeys()) 1033 return list(self.iterkeys())
1038 1034
1039 def __iter__(self) -> Iterator[bytes]: 1035 def __iter__(self) -> Iterator[bytes]:
1258 """Generates matching file names. 1254 """Generates matching file names.
1259 1255
1260 It also reports nonexistent files by marking them bad with match.bad(). 1256 It also reports nonexistent files by marking them bad with match.bad().
1261 """ 1257 """
1262 if match.always(): 1258 if match.always():
1263 for f in iter(self): 1259 yield from iter(self)
1264 yield f
1265 return 1260 return
1266 1261
1267 fset = set(match.files()) 1262 fset = set(match.files())
1268 1263
1269 for fn in self._walk(match): 1264 for fn in self._walk(match):
1294 fullp = self._subpath(p) 1289 fullp = self._subpath(p)
1295 if match(fullp): 1290 if match(fullp):
1296 yield fullp 1291 yield fullp
1297 else: 1292 else:
1298 if not visit or p[:-1] in visit: 1293 if not visit or p[:-1] in visit:
1299 for f in self._dirs[p]._walk(match): 1294 yield from self._dirs[p]._walk(match)
1300 yield f
1301 1295
1302 def _matches(self, match: matchmod.basematcher) -> 'treemanifest': 1296 def _matches(self, match: matchmod.basematcher) -> 'treemanifest':
1303 """recursively generate a new manifest filtered by the match argument.""" 1297 """recursively generate a new manifest filtered by the match argument."""
1304 if match.always(): 1298 if match.always():
1305 return self.copy() 1299 return self.copy()
1536 1530
1537 self._load() 1531 self._load()
1538 # OPT: use visitchildrenset to avoid loading everything. 1532 # OPT: use visitchildrenset to avoid loading everything.
1539 self._loadalllazy() 1533 self._loadalllazy()
1540 for d, subm in self._dirs.items(): 1534 for d, subm in self._dirs.items():
1541 for subtree in subm.walksubtrees(matcher=matcher): 1535 yield from subm.walksubtrees(matcher=matcher)
1542 yield subtree
1543 1536
1544 1537
1545 class manifestfulltextcache(util.lrucachedict): 1538 class manifestfulltextcache(util.lrucachedict):
1546 """File-backed LRU cache for the manifest cache 1539 """File-backed LRU cache for the manifest cache
1547 1540