#329 Simplify startswith and endswith calls.
Closed 5 years ago by qulogic. Opened 5 years ago by qulogic.
qulogic/FedoraReview startswith-endswith  into  devel

file modified
+4 -4
@@ -293,7 +293,7 @@ 

      def run(self):

          has_defattr = False

          for pkg in self.spec.packages:

-             if pkg.endswith('-debuginfo') or pkg.endswith('-debugsource'):

+             if pkg.endswith(('-debuginfo', '-debugsource')):

                  # auto-generated %defattr, ignore

                  continue

              for line in self.spec.get_files(pkg):
@@ -1120,7 +1120,7 @@ 

              if path.endswith('.src.rpm'):

                  return True

              pkg = path.rsplit('-', 2)[0]

-             return pkg.endswith('-debuginfo') or pkg.endswith('-debugsource')

+             return pkg.endswith(('-debuginfo', '-debugsource'))

  

          bad_owners_by_dir = {}

          rpm_files = glob(os.path.join(Mock.resultdir, '*.rpm'))
@@ -1132,7 +1132,7 @@ 

              for rpm_dir in rpm_dirs:

                  if '/usr/lib/.build-id' in rpm_dir:

                      continue

-                 if [d for d in my_dirs if rpm_dir.startswith(d)]:

+                 if rpm_dir.startswith(tuple(my_dirs)):

                      continue

                  owners = set(deps.list_owners(rpm_dir))

                  if owners.issubset(allowed):
@@ -1346,7 +1346,7 @@ 

          for pkg in self.spec.packages:

              if self.rpms.find('*.a', pkg):

                  names.append(pkg)

-                 if not (pkg.endswith('-static') or pkg.endswith('-devel')):

+                 if not pkg.endswith(('-static', '-devel')):

                      bad_names.append(pkg)

                  rpm_pkg = self.rpms.get(pkg)

                  ok = [r for r in rpm_pkg.provides if r.endswith('-static')]

file modified
+1 -2
@@ -52,8 +52,7 @@ 

          """

          self.log = Settings.get_logger()

  

-         if build_descriptor.startswith('http://') or \

-                build_descriptor.startswith('https://'):

+         if build_descriptor.startswith(('http://', 'https://')):

              build_id = self.parse_build_id_from_uri(build_descriptor)

          else:

              build_id = build_descriptor.lstrip('0')

file modified
+1 -1
@@ -138,7 +138,7 @@ 

  

          paths = self.get_package_rpm_paths(spec)

          tag = _get_tag(paths)

-         if not tag.startswith('fc') and not tag.startswith('el'):

+         if not tag.startswith(('fc', 'el')):

              tag = _get_tag_from_flags(self, flags)

          macros = _add_disttag_macros({}, tag)

          buildarch, macros = _add_buildarch_macros(macros, paths)

file modified
+1 -2
@@ -54,8 +54,7 @@ 

              href = href.encode('ascii', 'ignore').decode('ascii')

              if '?' in href:

                  href = href[0: href.find('?')]

-             if not href.startswith('http://') and \

-                     not href.startswith('https://'):

+             if not href.startswith(('http://', 'https://')):

                  href = self.bug_url + '/' + href

              if href.endswith(pattern):

                  found.append(href)

Both accept tuples of multiple things to check, instead of calling the method multiple times.

Looks good. But I haven't tested it yet.

rebased onto 7f24282

5 years ago

@qulogic Can you redo this against the master branch?

I guess I can't edit the target branch here, then?

Pull-Request has been closed by qulogic

5 years ago

@qulogic I guess not? Seems weird...