Favor clear, idiomatic Python over verbose, manual, or unpythonic constructs, and avoid introducing unnecessary complexity or unrelated refactors just to satisfy a linter/type-checker. Specifically:
[(category, x) for x in values] instead of map(lambda x: (category, x), values), use dict.update(other) instead of a manual union loop, use for i, x in enumerate(items) instead of manual indexing, and prefer for...else over manual “found” flags.return all(...) instead of if all(...): return True, or provide_automatic_options = "OPTIONS" not in methods instead of a multi-branch if/else that only sets a boolean.callable(obj) instead of hasattr(obj, '__call__'), isinstance(x, str) instead of type(x) is str, and == (never is) for comparing values like numbers or strings.t.cast() that doesn’t change the inferred type, an unnecessary import of a module already imported at module scope, or explicitly passing a default value (e.g. None) that’s already the implicit default.# type: ignore comment) over refactoring working code, especially in hot paths where extra variables/calls aren’t free.Example:
# Avoid
results = []
for category, values in flashes.items():
results += map(lambda x: (category, x), values)
# Prefer
results = [(category, x) for category, values in flashes.items() for x in values]
Applying this standard keeps diffs small, logic easy to scan, and avoids subtle bugs introduced by overly clever or needlessly verbose code.