"""Module names for the files a split creates: they say what the module holds, never how it was produced.""" # Added to a name that is already taken, in order; a number is the last resort and a name worth a human rename. DISAMBIGUATORS = ("more", "further", "extra", "additional", "other") def distinct(name, used, limit): """`name` (cut to `limit` characters) or the first `name_` that is not in `used`; the result joins `used`.""" candidate = name[:limit].rstrip("_") for word in DISAMBIGUATORS: if candidate not in used: break candidate = f"{name[:limit - len(word) - 1]}_{word}".lstrip("_") n = 2 while candidate in used: candidate, n = f"{name[:limit - 4]}_{DISAMBIGUATORS[-1]}_{n}", n + 1 used.add(candidate) return candidate