Skip to content

Commit

Permalink
"yield from", instead of "yield" in a loop
Browse files Browse the repository at this point in the history
This is a suggestion from pyupgrade:
https://github.com/asottile/pyupgrade#yield--yield-from
  • Loading branch information
DimitriPapadopoulos authored and abravalheri committed Nov 20, 2023
1 parent 0a640d7 commit 5069f6c
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2095,8 +2095,7 @@ def find_eggs_in_zip(importer, path_item, only=False):
if _is_egg_path(subitem):
subpath = os.path.join(path_item, subitem)
dists = find_eggs_in_zip(zipimport.zipimporter(subpath), subpath)
for dist in dists:
yield dist
yield from dists
elif subitem.lower().endswith(('.dist-info', '.egg-info')):
subpath = os.path.join(path_item, subitem)
submeta = EggMetadata(zipimport.zipimporter(subpath))
Expand Down Expand Up @@ -2131,8 +2130,7 @@ def find_on_path(importer, path_item, only=False):
for entry in sorted(entries):
fullpath = os.path.join(path_item, entry)
factory = dist_factory(path_item, entry, only)
for dist in factory(fullpath):
yield dist
yield from factory(fullpath)


def dist_factory(path_item, entry, only):
Expand Down Expand Up @@ -2850,8 +2848,7 @@ def _get_metadata_path_for_display(self, name):

def _get_metadata(self, name):
if self.has_metadata(name):
for line in self.get_metadata_lines(name):
yield line
yield from self.get_metadata_lines(name)

def _get_version(self):
lines = self._get_metadata(self.PKG_INFO)
Expand Down

1 comment on commit 5069f6c

@jaraco
Copy link
Member

@jaraco jaraco commented on 5069f6c Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this change. Do be aware there are known differences in behavior in select cases (asottile/pyupgrade#659), particularly if the generator isn't expected to be fully consumed. I doubt that's the case with these changes, so no need to spend more time on it, but I wanted to share for a broader understanding of this risk.

Please sign in to comment.