Skip to content

Commit 027a83d

Browse files
committed
invert logic: return early
1 parent 7a7f1d3 commit 027a83d

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

gazelle/python/generate.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -658,17 +658,19 @@ func generateProtoLibraries(args language.GenerateArgs, cfg *pythonconfig.Config
658658
// file names if GeneratePyiSrcs is set. Otherwise, returns an empty set.
659659
func getPyiFilenames(filenames *treeset.Set, generatePyiSrcs bool, basePath string) (*treeset.Set, error) {
660660
pyiSrcs := treeset.NewWith(godsutils.StringComparator)
661-
if generatePyiSrcs {
662-
it := filenames.Iterator()
663-
for it.Next() {
664-
pyiFilename := it.Value().(string) + "i" // foo.py --> foo.pyi
661+
if !generatePyiSrcs {
662+
return pyiSrcs, nil
663+
}
665664

666-
_, err := os.Stat(filepath.Join(basePath, pyiFilename))
667-
// If the file DNE or there's some other error, there's nothing to do.
668-
if err == nil {
669-
// pyi file exists, add it
670-
pyiSrcs.Add(pyiFilename)
671-
}
665+
it := filenames.Iterator()
666+
for it.Next() {
667+
pyiFilename := it.Value().(string) + "i" // foo.py --> foo.pyi
668+
669+
_, err := os.Stat(filepath.Join(basePath, pyiFilename))
670+
// If the file DNE or there's some other error, there's nothing to do.
671+
if err == nil {
672+
// pyi file exists, add it
673+
pyiSrcs.Add(pyiFilename)
672674
}
673675
}
674676
return pyiSrcs, nil

0 commit comments

Comments
 (0)