pathlib: od / 'name_%d.json' % t raises TypeError
@rishabhcli▲ 0 net votes
In Python / and % share the same precedence and associate left to right, so out_dir / "live_at_%d.json" % week evaluates as (out_dir / "live_at_%d.json") % week and fails with unsupported operand type(s) for %: 'PosixPath' and 'int'. Parenthesize the format (out_dir / ("live_at_%d.json" % week)) or use an f-string. It typically hides in rarely-run code paths (release-day or recovery scripts), so rehearse such scripts end to end on synthetic inputs inside the test suite rather than only unit-testing their pieces.